Code Monkey home page Code Monkey logo

Comments (6)

thomaxxl avatar thomaxxl commented on August 13, 2024 1

I used this to create a gis db: http://www.jennifergd.com/post/7/

The json encoding can be implemented with a custom JSONEncoder:
https://gist.github.com/thomaxxl/53256daf0c94b53832fd6cc1959a1451

There also seems to be a geojson format that I can use, I'll check for that and the decoding later.

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

Hi,

can you provide me with a sample database and sqla models? Then I'll have a look.
I created some custom types here: https://github.com/thomaxxl/safrs/blob/master/safrs/safrs_types.py I guess

I think the approach would be similar.

from safrs.

tomaswangen avatar tomaswangen commented on August 13, 2024

Hi,

You can find a preconfigured postgres/postgis installation with a ready-to-use db "gis" here:

https://hub.docker.com/r/kartoza/postgis/

Assuming you run it with:
docker run --name "postgis" -p 25432:5432 -d -t kartoza/postgis

the corresponding connection string for the preconfigured db is:

postgresql://docker:docker@localhost:25432/gis

A minimal schema including a geometry column:

# pip install GeoAlchemy2

from geoalchemy2 import Geometry
class FooBar(SAFRSBase, db.Model):
    __tablename__ = 'FooBar'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    geom = db.Column(Geometry('POINT', srid=25833, dimension=2))

    def __init__(self, geom):
        self.geom = geom

A sample body for POST (which should successfully execute the INSERT):

{
  "data": {
    "attributes": {
      "geom": "SRID=25833;POINT(-71.064544 42.28787)"
    },
    "type": "FooBar"
  }
}

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

You can implement the POST/INSERT like this:

https://gist.github.com/thomaxxl/53256daf0c94b53832fd6cc1959a1451#file-geo1-py-L29-L34

Does this work for you?

I may add this to safrs eventually, but I don't know the geo types well enough.

from safrs.

tomaswangen avatar tomaswangen commented on August 13, 2024

Thank you for the impressively efficient work on this :)

The insert can also be done with the native representation:

"geom": "SRID=25833;POINT(-71.064544 42.28787)"

Decoding to the same format can similarly be done using (in sql syntax)

concat('SRID=',ST_SRID(geom), ';', ST_AsText(geom))

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

I implemented this with json encoding here:
https://github.com/thomaxxl/safrs/wiki/Postgis-Geoalchemy2 . I changed the safrs code a bit so I am able to add a sample value for the custom column type that will be rendered in the swagger
sample = {"coordinates": [-122.43129, 37.773972], "type": "Point"}

I guess you are able to figure out everything yourself.. if there's something else feel free to reopen or open a new issue.

from safrs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.