[GeoJSON] AsJSON(geometry)

Sean Gillies sgillies at frii.com
Sat Mar 17 12:40:28 PDT 2007


Paul Ramsey wrote:
> My interest in this subject is solely so that I can add an AsJSON() and 
> GeometryFromJSON() functions to PostGIS to make life easier for people 
> writing scripting access to the database.  A recent experience with 
> writing a quick'n'dirty KML service really hammered home how utility 
> functions like these can make scripters lives easier.
> 
> I see there's a simple draft on the wiki already, which goes all the way 
> to the feature model.  All the AsJSON() function would do is the 
> geometry part: would you say the geometry representation is largely set?
> 
> So,
> 
> AsJSON(GeometryFromText('POLYGON(((0 0 0, 1 0 0, 1 1 0, 0 1 0, 0 0 
> 0)))',4326))
> 
> would return
> 
> "polygon": [[[0.0, 0.0, 0.0] [1.0, 0.0, 0.0] [1.0, 1.0, 0.0] [0.0, 1.0, 
> 0.0] [0.0, 0.0, 0.0]]]
> 
> At some point you should note that "the behavior of our rings and vertex 
> arrays is meant to follow the semantics defined in the OGC SF model" (no 
> interior/exterior ring intersections, except at a single point) . Are 
> you planning on distinguishing between POLYGON and MULTIPOLYGON or going 
> for a more Shapefileish "always a MULTIPOLYGON" model?
> 
> P
> 

Paul, I'm not ready for anything to be set in stone, and I think we can 
do better than that particular JSON representation. I'm happy with the 
OGC SF model and the distinction between polygon and multipolygon.

I'm not sure how polygons and multipolygons should be expressed, but I 
think that simpler geometries should be no more complex than

   {"type": "point", "value": [x1, x2, x3]}
   {"type": "line",  "value": [[x11, x12, x13], ..., [xN1, xN2, xN3]]}

One object with no children. Coordinates as arrays of numbers.

In my own work, I'm going to need multipoints before polygons or 
multipolygons, and so that's what I've been thinking about lately. 
Perhaps multi types would have geometry "members":

   {"type": "multipoint", "members": [
     {"type": "point", ...},
     {"type": "point", ...}
     ]
   }

Cheers,
Sean

-- 
Sean Gillies
http://zcologia.com/news




More information about the GeoJSON mailing list