I'm trying to read this GeoJSON from this string:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[-69.0062266588211,
9.27562217679211],
[-43.517945408821106,
-2.811371193331128],
[-37.014039158821106,
-9.795677582829732],
[-72.61157142049046,
4.701436497353403],
[-69.0062266588211,
9.27562217679211]]]
},
"properties": {
"name": "DOUBLE OAKS CENTER",
"address": "1326 WOODWARD AV"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-80.837753,
35.249801
]
},
"properties": {
"name": "DOUBLE OAKS CENTER",
"address": "1326 WOODWARD AV"
}
}
]
}
Via this code:
@SuppressWarnings("unchecked")
public static final FeatureCollection<SimpleFeatureType, SimpleFeature> jsonToFeatureCollection(String jsonContent) throws IOException{
GeometryJSON geometryJson = new GeometryJSON(15);
FeatureJSON featureJson = new FeatureJSON(geometryJson);
Reader stringReader = null;
@SuppressWarnings("rawtypes")
FeatureCollection featureCollection = null;
try{
stringReader = new StringReader(jsonContent);
featureCollection = featureJson.readFeatureCollection(stringReader);
}finally{
stringReader.close();
}
return featureCollection;
}
And then re-printing it to check if all is fine, but it seems I don't get the same data that was in the string. In the specific the second geometry that is a Point is reported as a Polygon (with correct coordinates, just repeated geometry=POLYGON ((-80.837753 35.249801, -80.837753 35.249801, -80.837753 35.249801, -80.837753 35.249801))
I print data via this code:
featureCollection = MarshallingTool.jsonToFeatureCollection(this.jsonContent);
featureIterator = featureCollection.features();
System.out.println("#### FEATURE COLLECTION ####");
System.out.println("FeatureCollection: size:" + featureCollection.size());
System.out.println("FeatureCollection: ID:" + featureCollection.getID());
System.out.println("FeatureCollection: Name:" + featureCollection.getSchema().getName().toString());
//System.out.println("FeatureCollection: ID:" + featureCollection.getSchema().getCoordinateReferenceSystem().toWKT());
while(featureIterator.hasNext()){
aFeature = (SimpleFeature) featureIterator.next();
System.out.println("######## FEATURE #######");
//System.out.println("Name:" + aFeature.getName());
System.out.println("2" + aFeature.getType().getGeometryDescriptor().getName());
System.out.println("3" + aFeature.getDefaultGeometryProperty().getType().getName().getLocalPart());
System.out.println("4" + aFeature.getIdentifier().getID());
System.out.println("5" + aFeature.getType());
System.out.println("6" + aFeature.getDefaultGeometryProperty());
System.out.println("7" + aFeature.getDefaultGeometry());
Map<Object, Object> userData = aFeature.getUserData();
Collection<Property> properties = aFeature.getProperties();
for(Property property:properties){
System.out.println(property.getName() + "=" + property.getValue());
}
Set<Object> keys = userData.keySet();
for(Object aKey:keys){
System.out.println(aKey + "=" + userData.get(aKey));
}
System.out.println("##############");
}
And when I re-print it I get instead:
#### FEATURE COLLECTION ####
FeatureCollection: size:2
FeatureCollection: ID:featureCollection
FeatureCollection: Name:http://geotools.org:feature
######## FEATURE #######
2geometry
3geometry
4feature-0
5SimpleFeatureTypeImpl http://geotools.org:feature identified extends Feature(name:name,address:address,geometry:geometry)
6GeometryAttributeImpl:geometry=POLYGON ((-69.0062266588211 9.27562217679211, -43.517945408821106 -2.811371193331128, -37.014039158821106 -9.795677582829732, -72.61157142049046 4.701436497353403, -69.0062266588211 9.27562217679211))
7POLYGON ((-69.0062266588211 9.27562217679211, -43.517945408821106 -2.811371193331128, -37.014039158821106 -9.795677582829732, -72.61157142049046 4.701436497353403, -69.0062266588211 9.27562217679211))
name=POLIGON DOUBLE OAKS CENTER
address=POLIGON 1326 WOODWARD AV
geometry=POLYGON ((-69.0062266588211 9.27562217679211, -43.517945408821106 -2.811371193331128, -37.014039158821106 -9.795677582829732, -72.61157142049046 4.701436497353403, -69.0062266588211 9.27562217679211))
##############
######## FEATURE #######
2geometry
3geometry
4feature-1
5SimpleFeatureTypeImpl http://geotools.org:feature identified extends Feature(name:name,address:address,geometry:geometry)
6GeometryAttributeImpl:geometry=POLYGON ((-80.837753 35.249801, -80.837753 35.249801, -80.837753 35.249801, -80.837753 35.249801))
7POLYGON ((-80.837753 35.249801, -80.837753 35.249801, -80.837753 35.249801, -80.837753 35.249801))
name=POINT DOUBLE OAKS CENTER
address=POINT 1326 WOODWARD AV
geometry=POLYGON ((-80.837753 35.249801, -80.837753 35.249801, -80.837753 35.249801, -80.837753 35.249801))
##############
Is it possible that the JSON part of the GeoTools API has an issue? Do you see anything wrong in the way I read the string or in how I print the content ?