Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#9566 closed (fixed)

GeoJSON regexes doesn't accept leading and trailing whitespace or GeometryCollections

Reported by: jbronn Owned by: jbronn
Component: GIS Version: 1.0
Severity: Keywords: gis geojson gdal
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by jbronn)

from django.contrib.gis import gdal

json1 = '{ "type": "MultiPolygon", "coordinates": [ [ [ [ 102.000000, 2.000000 ], [ 103.000000, 2.000000 ], [ 103.000000, 3.000000 ], [ 102.000000, 3.000000 ], [ 102.000000, 2.000000 ] ] ], [ [ [ 100.000000, 0.000000 ], [ 101.000000, 0.000000 ], [ 101.000000, 1.000000 ], [ 100.000000, 1.000000 ], [ 100.000000, 0.000000 ] ], [ [ 100.200000, 0.200000 ], [ 100.800000, 0.200000 ], [ 100.800000, 0.800000 ], [ 100.200000, 0.800000 ], [ 100.200000, 0.200000 ] ] ] ] }'

json2 = """

{ "type": "MultiPolygon",
  "coordinates": [
    [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
    [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
     [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
    ]
  }

"""

g1 = gdal.OGRGeometry(json1)
g2 = gdal.OGRGeometry(json2)

Trying to execute this raises this:

Traceback (most recent call last):
  File "geojson_regex.py", line 18, in <module>
    g2 = gdal.OGRGeometry(json2)
  File "/Users/jbronn/django/1.0.X/django/contrib/gis/gdal/geometries.py", line 106, in __init__
    ogr_t = OGRGeomType(geom_input)
  File "/Users/jbronn/django/1.0.X/django/contrib/gis/gdal/geomtype.py", line 29, in __init__
    raise OGRException('Invalid OGR String Type "%s"' % type_input)
django.contrib.gis.gdal.error.OGRException: Invalid OGR String Type "

{ "type": "MultiPolygon",
  "coordinates": [
    [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
    [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
     [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
    ]
  }

"

Oh, and did I mention because the { and } characters aren't accepted, it can't parse the GeoJSON of geometry collections.

Attached is patch that improves the GeoJSON regex situation in the GDAL and GEOS libraries.

Attachments (1)

geojson_regex.diff (5.0 KB) - added by jbronn 6 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by jbronn

  • Component changed from Uncategorized to GIS
  • Keywords gis geojson gdal added
  • milestone set to post-1.0
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to jbronn
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by jbronn

  • Description modified (diff)
  • Summary changed from GeoJSON regexes doesn't accept leading and trailing whitespace to GeoJSON regexes doesn't accept leading and trailing whitespace or GeometryCollections

comment:3 Changed 6 years ago by jbronn

  • Has patch set
  • Needs tests set

Changed 6 years ago by jbronn

comment:4 Changed 6 years ago by jbronn

  • Resolution set to fixed
  • Status changed from new to closed

(In [9392]) Fixed #9566 -- made GeoJSON regex more robust.

comment:5 Changed 6 years ago by jbronn

(In [9393]) [1.0.X] Fixed #9566 -- made GeoJSON regex more robust.

Backport of r9392 from trunk.

comment:6 Changed 6 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top