Skip to content

Added support for Geometry in Postgres/PostGIS - #3699

Closed
Ghirro wants to merge 7 commits into
sequelize:masterfrom
Ghirro:master
Closed

Ghirro wants to merge 7 commits into
sequelize:masterfrom
Ghirro:master

Conversation

@Ghirro

@Ghirro Ghirro commented May 12, 2015

Copy link
Copy Markdown

Hi there,

So we use sequelize internally and required Geometry support to some degree. I started adding it in a few days ago before I realised that someone had already done a little bit of the work [https://github.com//pull/3641]. We were actually moving along the same path (using GeoJSON) and that PR had a few approaches that were better than my own and so I integrated them here.

A couple of things to note, I've had to change one test to run locally. I looked it up and it's a known issue (#2966). I also ran into a few issues with the documentation generation suite but have documented what I've done.

The basics are:


Added support for DataTypes.GEOMETRY(Type, SRID)

This will be stored as a POSTGIS geometry column but the API will always interacts with GeoJSON


Added support for new geo based where lookups:

$geoIn: { GeoJson } // Returns when given object contains row
$geoNotIn: { GeoJson } // Returns when given object doesn't contain row
$geoWithin: { point: { GeoJson }, distance: 10 } // Returns when given object is within distance of point
$geoWithout: { point: { GeoJson }, distance: 10 } // Returns when given object is not within distance of point

I've also had to slightly change the dropTables for postgres as this did not work well with the new tests I've introduced (tried to drop POSTGIS views which are vital).

Anyway apologies for a slightly overlapping pull request but I thought it better to mention it.

@Ghirro

Ghirro commented May 12, 2015

Copy link
Copy Markdown
Author

Sorry worth also noting that if you're a relatively new GeoJSON/Postgis user then you'll need to specify the SRID on the GeoJson objects when inserting (from there they'll be retrieved automatically). An example is:

var GeoJSON = {
  type: 'Point',
  coordinates: [ 54.57, 41.29 ],
  crs : {
    type: 'name',
    properties: {
      'name' : 'EPSG:4326'
    }
  }
}

The crs property is the SRID info. If you don't include this you may start getting some hokey error messages about clashing SRIDs.

@janmeier

Copy link
Copy Markdown
Member

I don't have time to review this yet, but it may be duplicate of #3641 and my comments there probably apply to that as well

edit: I didn't notice that you already mentioned the other PR, sorry :). But my comment there about supporting geoJSON in other dialects still applies - I think it could be done with very little extra work

@janmeier janmeier self-assigned this May 15, 2015
@gtg092x

gtg092x commented May 19, 2015

Copy link
Copy Markdown

Any updates on this? I'm actually interested in using this branch. I found the PR while trying to hack together an almost identical solution. Specifically, anything that would keep this from getting merged?

@Ghirro

Ghirro commented May 20, 2015

Copy link
Copy Markdown
Author

It's currently being prevented from being merged because it only works in Postgres and the more sensible thing to do is to use WKT to make it work alongside other SQL geometries. I've made a start on it and hope to get it done this weekend.

@mappagnosis

Copy link
Copy Markdown

I'd like to offer my encouragement for this development. It is a very valuable extension of the functionality of Sequelize and I am keen to see it merged. Janmeier makes some great comments in #3641 and to the 'wants' list of mysql and mssql you could add spatialite, which is the spatial enablement of sqlite3. However, even just having the PostGIS functionality is such a major bonus that perhaps it is worth merging now while waiting on the addition of support for other databases. I would advocate keeping the native PostGIS functionality and adding the WKT support in addition rather than seeing compliance with the request for WKT as an alternative.

@mshahriarinia

Copy link
Copy Markdown

Any updates on this?

@janmeier

Copy link
Copy Markdown
Member

Closed in favor of #3828

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants