Create a geometry from GeoJSON array

742 views
Skip to first unread message

Andrew Jeffrey

unread,
Mar 2, 2014, 7:25:17 PM3/2/14
to jsts...@googlegroups.com
Hi,

I am having trouble with the GeoJSONReader.

Basically all I want to do is buffer a point and perform an intersection between the buffer and another point file. I get the point from my user as WKT and use the WKTReader to create a geometry and store it in a variable called "userpoint". I then buffer user point and store that as the variable "userbuffer" by doing "userbuffer = userpoint.buffer(1000);" All good up until here!

I then have a GeoJSON array (created from QGIS) with a heap of points in there, I want to perform an intersection between the buffer and the GeoJSON array to see what points are inside the buffered area. I tried using the jsts.io.GeoJSONReader to convert my GeoJSON to a geometry but the result just gives me an array with none of the methods that a jsts.geom.Geometry object has. From the API documentation I expected the GeoJSONReader to return me a geometry object with my data, but I don't think that is what I have.

I have attached my js file which has the json array. I have declared the variable globally and I can see and access an array after using the GeoJSONReader, but like I said it has no methods that go with a geometry.

New to jsts but keen to learn more about it. Any help on how to get this array as a geometry so I can perform an intersection would be greatly appreciated.

Thanks

Andrew
layer.js

Björn

unread,
Mar 3, 2014, 1:44:12 PM3/3/14
to jsts...@googlegroups.com
Should work. Can you provide a complete failing example, preferably with a bit smaller GeoJSON?

/Björn

Andrew Jeffrey

unread,
Mar 3, 2014, 3:54:26 PM3/3/14
to jsts...@googlegroups.com
Hey Bjorn,

I have attached a working example - I have commented the code explaining what I am trying to do. You made need to fix the script reference to jsts, I couldn't find a hosted one.

Maybe I am just interpreting the docco wrong. Once I read GeoJSON in using the GeoJSON reader I should have a jsts.geom.Geometry object right?

Thanks for the speedy response.

Andrew


--
You received this message because you are subscribed to a topic in the Google Groups "JSTS devs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsts-devs/TYpT2mzWQA0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsts-devs+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

index.zip

Björn

unread,
Mar 5, 2014, 5:16:01 AM3/5/14
to jsts...@googlegroups.com
The GeoJSON reader produces different outputs depending on what GeoJSON is parsed. A GeoJSON geometry should come out as a jsts.geom.Geometry, a GeoJSON feature will be represented by an object containing geometry and properties and a GeoJSON feature collection will be an array of feature objects and this is why your short solution does not work. There is nothing wrong with the longer solution but perhaps you could rewrite it first converting the array of feature objects into a jsts.geom.GeometryCollection then use that with the intersection method. If you use the Array map method the code for this could be quite short.

/Björn

Andrew Jeffrey

unread,
Mar 5, 2014, 6:53:41 PM3/5/14
to jsts...@googlegroups.com
Awesome thanks for the explanation, that makes sense having it put like that. I will try the suggestion of pushing the array values into a geometry collection.

This JS library is freakin awesome by the way - top job!
Message has been deleted

Siva ram

unread,
Feb 17, 2016, 7:41:01 AM2/17/16
to JSTS devs
Hi Bjorn,

I could see that this is an old thread but I'm facing the same problem reading the GeoJson object using the GeoJSONReader class. I'm getting the following error in the Google chrome console.

"Uncaught TypeError: Cannot read property 'FeatureCollection' of undefined". Please have a look at this JSFiddle sample and let me know what's the problem.

Thanks
Ram

Björn

unread,
Feb 17, 2016, 5:40:26 PM2/17/16
to JSTS devs
GeoJSON Features and/or FeatureCollections are not supported, only Geometry types.

Siva ram

unread,
Feb 18, 2016, 1:44:02 AM2/18/16
to JSTS devs
Hi Bjorn,

Thanks for the quick response. But you have mentioned that the GeoJson Feature and FeatureCollection objects will be converted to feature and array of feature objects respectively

a GeoJSON feature will be represented by an object containing geometry and properties and a GeoJSON feature collection will be an array of feature objects

and also I could see the GeoJSONParser class(which is used by the GeoJSONReader) is containing a "parse" method which is handling "Feature" and "FeatureCollection" types as well.

Could you please let me know if this behavior has been changed recently as we are looking forward to use JSTS library for GeoJson data processing.

Thanks
Ram

Björn

unread,
Feb 18, 2016, 7:33:43 AM2/18/16
to JSTS devs
I think it does not make good sense to read/write features into JTS/JSTS since it models Geometries not Features and would have to drop the Feature related data anyway.

Siva ram

unread,
Feb 19, 2016, 12:59:51 AM2/19/16
to JSTS devs
Hi Bjorn,

Oh Ok. I was expecting that the GeoJSONReader will parse any GeoJson data from it's name and the source code. I will change my code accordingly and thanks for your explanation. Currently I'm facing one more issue with distance calculation and I will post it in a different thread.

Thanks
Ram
Reply all
Reply to author
Forward
0 new messages