Closed smirnovegorv closed 2 years ago
Actually created a pull request. Simply renamed a dependency and updated version to 2.0 since this is a major breaking change.
Hello, I have seen your geogson-core and geogson-jts libraries on Internet and I wanted to know if you could help me, because I have not found much information or examples. I have a File in GEO-JSON format with many polygons and multipolygons and I want to go through them one by one to know which contains a coordinate (latitude and longitude). I would like to be able to obtain JTS objects to use the contains(point) method and also obtain the specific properties of the polygon where the coordinate is located. Thanks in advance, regards.
I have a File in GEO-JSON format with many polygons and multipolygons and I want to go through them one by one to know which contains a coordinate (latitude and longitude). I would like to be able to obtain JTS objects to use the contains(point) method and also obtain the specific properties of the polygon where the coordinate is located.
You need to set up Gson instance using geogson adapters like
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(new GeometryAdapterFactory())
.registerTypeAdapterFactory(new JtsAdapterFactory())
.create();
Then just read your file as a usual json using this instance. Your root object will most likely be a com.github.filosganga.geogson.model.FeatureCollection object, which has Feature list inside, and Features have Geometry field.
Hello again. This is my code, and commented, my problem:
` Gson gson = new GsonBuilder() .registerTypeAdapterFactory(new JtsAdapterFactory()) .registerTypeAdapterFactory(new GeometryAdapterFactory()) .create();
FileReader fileReader = new FileReader("municipios_es21.json");
FeatureCollection collection = gson.fromJson(fileReader, FeatureCollection.class);
List
for (Feature feature : featureList) { // I want to know if feature is Polygon or MultiPolygon, and instantiate an object , // because Polygon & MultiPolygon don't have contains() metod !! // but JTS objects yes they have this metod... if (polygon.contains(point) || multiPolygon.contains(point)) { propMap = feature.properties(); System.out.println(propMap.get("NATCODE")); System.out.println(propMap.get("NAMEUNIT")); break; } } ` Maybe I'm not used to these libraries, but this is basically my doubt. Thank you very much, really.
Geogson geometry objects have a type field which can give you their real geometry type. Or you may use instanceof operator to get the real geometry class. Actually I did not use geogson for reading geojson files, I only used it to convert JTS geometry objects to and from geojson. So I was always receiving the JTS Geometry object and did not work with geogson model classes
If you view muy code, this is my problem, how to convert geojson file into JTS objects. I know the type of Geometry with instanceof, but I don't know how cast to JTS Polygon or MultiPolygon. Thx.
El lun, 27 de mayo de 2019 22:55, jedi-philosopher notifications@github.com escribió:
Geogson geometry objects have a type field which can give you their real geometry type. Or you may use instanceof operator to get the real geometry class. Actually I did not use geogson for reading geojson files, I only used it to convert JTS geometry objects to and from geojson. So I was always receiving the JTS Geometry object and did not work with geogson model classes
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/filosganga/geogson/issues/65?email_source=notifications&email_token=ACZWGZGBZUHVB6WIJ2RGOMDPXRDFJA5CNFSM4GTJ3DLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWKQAWI#issuecomment-496304217, or mute the thread https://github.com/notifications/unsubscribe-auth/ACZWGZFFOTFP4WAS3CCS5HDPXRDFJANCNFSM4GTJ3DLA .
Any chance we can get the version update/current master in a release?
Sorry for the huge delay, it has been released on maven central with 1.18
Some time ago JTS has changed their artifact package. It was com.vividsolution.jts and now it is org.locationtech.jts. Ongoing development and new versions (latest one now is 1.16.0) will only appear as org.locationtech now.
So it will be nice to have geogson support new artifact version with new package names.
https://gis.stackexchange.com/questions/246588/difference-in-jts-from-vivid-solution-and-locationtech https://github.com/locationtech/jts/blob/master/MIGRATION.md