Skip to content

Support SRID on geometry, and with WKT/B Reader/Writers#132

Closed
mwtoews wants to merge 1 commit intoshapely:masterfrom
mwtoews:master
Closed

Support SRID on geometry, and with WKT/B Reader/Writers#132
mwtoews wants to merge 1 commit intoshapely:masterfrom
mwtoews:master

Conversation

@mwtoews
Copy link
Copy Markdown
Member

@mwtoews mwtoews commented May 14, 2014

A few notes:

  • If SRID=0, it is not written to either WKT or WKB, regardless of 'include_srid' setting
  • SRID ranges are not checked, as PostGIS does. E.g., the valid range is between 0 and I think 999998
  • SRID support for the WKT Reader/Writer is 100% Python, since it isn't in GEOS
  • SRID support for the WKB Reader/Writer is 100% GEOS C API

Currently, I set 'include_srid'=True as default for both writers, which may not be popular. However, I don't expect any surprises since this would only be written with geometries that somehow have set the SRID attribute data, which before now was to load WKB where it is set.

Here's a short demo of the current capabilities:

from shapely.wkt import loads as load_wkt
from shapely.wkb import loads as load_wkb
p1 = load_wkt('POINT(0 0)')
p2 = load_wkt('SRID=4326;POINT(0 0)')
print(p1.srid)  # 0
print(p2.srid)  # 4326
print(p1.wkb_hex)  # 010100000000000000000000000000000000000000
print(p2.wkb_hex)  # 0101000020E610000000000000000000000000000000000000
print(p1.wkt)  # POINT (0 0)
print(p2.wkt)  # SRID=4326;POINT (0 0)
# Change values
p1.srid = -10000000
p2.srid = 0
print(p1.wkt)  # SRID=-10000000;POINT (0 0)
print(p2.wkt)  # POINT (0 0)
print(load_wkb(p1.wkb).wkt)  # SRID=-10000000;POINT (0 0)
print(load_wkb(p2.wkb).wkt)  # POINT (0 0)
print(load_wkb(p1.wkb_hex, hex=True).wkt)  # SRID=-10000000;POINT (0 0)
print(load_wkb(p2.wkb_hex, hex=True).wkt)  # POINT (0 0)

Currently, I set 'include_srid'=True as default, which may not be popular.
@sgillies
Copy link
Copy Markdown
Contributor

@mwtoews I've been -1 on SRID in Shapely since the start and would need to see a compelling use case before I'll reverse myself. As far as reading and writing WKT/WKB goes, how about simply adding an srid keyword arg to the dumps() functions? To be used like:

from shapely.geometry import Point
from shapely.wkt import dumps

dumps(Point(0, 0), srid=26915)

This would satisfy users' need to extend the well known formats but also keep Shapely geometries free of srid attributes.

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.

2 participants