Getting coordinates from GeoJson
up vote
0
down vote
favorite
I have geojson layer in my app. It's being loaded dynamically. Basically, I need to add marker to all geojson features so I need "position".
I have loop like this :
for (GeoJsonFeature feature : layer.getFeatures())
feature.setPolygonStyle(polygonStyle);
But I have no idea how to get coordinates from feature. I've tried this method :
private List<LatLng> getCoordinatesFromGeometry(Geometry geometry)
List<LatLng> coordinates = new ArrayList<>();
// GeoJSON geometry types:
// http://geojson.org/geojson-spec.html#geometry-objects
switch (geometry.getGeometryType())
case "Point":
coordinates.add(((GeoJsonPoint) geometry).getCoordinates());
break;
case "MultiPoint":
List<GeoJsonPoint> points = ((GeoJsonMultiPoint) geometry).getPoints();
for (GeoJsonPoint point : points)
coordinates.add(point.getCoordinates());
break;
case "LineString":
coordinates.addAll(((GeoJsonLineString) geometry).getCoordinates());
break;
case "MultiLineString":
List<GeoJsonLineString> lines =
((GeoJsonMultiLineString) geometry).getLineStrings();
for (GeoJsonLineString line : lines)
coordinates.addAll(line.getCoordinates());
break;
case "Polygon":
List<? extends List<LatLng>> lists =
((GeoJsonPolygon) geometry).getCoordinates();
for (List<LatLng> list : lists)
coordinates.addAll(list);
break;
case "MultiPolygon":
List<GeoJsonPolygon> polygons =
((GeoJsonMultiPolygon) geometry).getPolygons();
for (GeoJsonPolygon polygon : polygons)
for (List<LatLng> list : polygon.getCoordinates())
coordinates.addAll(list);
break;
return coordinates;
However it doesn't seems to work. Any help, please ?
android geojson
add a comment |
up vote
0
down vote
favorite
I have geojson layer in my app. It's being loaded dynamically. Basically, I need to add marker to all geojson features so I need "position".
I have loop like this :
for (GeoJsonFeature feature : layer.getFeatures())
feature.setPolygonStyle(polygonStyle);
But I have no idea how to get coordinates from feature. I've tried this method :
private List<LatLng> getCoordinatesFromGeometry(Geometry geometry)
List<LatLng> coordinates = new ArrayList<>();
// GeoJSON geometry types:
// http://geojson.org/geojson-spec.html#geometry-objects
switch (geometry.getGeometryType())
case "Point":
coordinates.add(((GeoJsonPoint) geometry).getCoordinates());
break;
case "MultiPoint":
List<GeoJsonPoint> points = ((GeoJsonMultiPoint) geometry).getPoints();
for (GeoJsonPoint point : points)
coordinates.add(point.getCoordinates());
break;
case "LineString":
coordinates.addAll(((GeoJsonLineString) geometry).getCoordinates());
break;
case "MultiLineString":
List<GeoJsonLineString> lines =
((GeoJsonMultiLineString) geometry).getLineStrings();
for (GeoJsonLineString line : lines)
coordinates.addAll(line.getCoordinates());
break;
case "Polygon":
List<? extends List<LatLng>> lists =
((GeoJsonPolygon) geometry).getCoordinates();
for (List<LatLng> list : lists)
coordinates.addAll(list);
break;
case "MultiPolygon":
List<GeoJsonPolygon> polygons =
((GeoJsonMultiPolygon) geometry).getPolygons();
for (GeoJsonPolygon polygon : polygons)
for (List<LatLng> list : polygon.getCoordinates())
coordinates.addAll(list);
break;
return coordinates;
However it doesn't seems to work. Any help, please ?
android geojson
"But I have no idea how to get coordinates from feature. " Referring to http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/geojson/GeoJsonFeature.html aGeoJSONFeature
has thegetGeometry()
method which gives you aGeoJsonGeometry
which is one of the geometry types like a point, line, multiline etc. and you already have the code for extracting the individual coordinate points from those. So, what is the problem?
– Markus Kauppinen
2 days ago
1
I suppose you want just one marker for each feature. Then of course extracting all the coordinate points is a starting point but not enough. You need to decice how you want to decide the marker location for a feature. You could have a look at calculating the bounding box for a feature and then calculating the middle point of the bounding box. I'm not sure this is the solution, but at least something to consider.
– Markus Kauppinen
2 days ago
Of course if the GeoJSON features are quite small (in relation to expected map zoom levels) it might be enough to just pick one of the coordinate points e.g. the first one and then there's no point in anything more elaborate.
– Markus Kauppinen
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have geojson layer in my app. It's being loaded dynamically. Basically, I need to add marker to all geojson features so I need "position".
I have loop like this :
for (GeoJsonFeature feature : layer.getFeatures())
feature.setPolygonStyle(polygonStyle);
But I have no idea how to get coordinates from feature. I've tried this method :
private List<LatLng> getCoordinatesFromGeometry(Geometry geometry)
List<LatLng> coordinates = new ArrayList<>();
// GeoJSON geometry types:
// http://geojson.org/geojson-spec.html#geometry-objects
switch (geometry.getGeometryType())
case "Point":
coordinates.add(((GeoJsonPoint) geometry).getCoordinates());
break;
case "MultiPoint":
List<GeoJsonPoint> points = ((GeoJsonMultiPoint) geometry).getPoints();
for (GeoJsonPoint point : points)
coordinates.add(point.getCoordinates());
break;
case "LineString":
coordinates.addAll(((GeoJsonLineString) geometry).getCoordinates());
break;
case "MultiLineString":
List<GeoJsonLineString> lines =
((GeoJsonMultiLineString) geometry).getLineStrings();
for (GeoJsonLineString line : lines)
coordinates.addAll(line.getCoordinates());
break;
case "Polygon":
List<? extends List<LatLng>> lists =
((GeoJsonPolygon) geometry).getCoordinates();
for (List<LatLng> list : lists)
coordinates.addAll(list);
break;
case "MultiPolygon":
List<GeoJsonPolygon> polygons =
((GeoJsonMultiPolygon) geometry).getPolygons();
for (GeoJsonPolygon polygon : polygons)
for (List<LatLng> list : polygon.getCoordinates())
coordinates.addAll(list);
break;
return coordinates;
However it doesn't seems to work. Any help, please ?
android geojson
I have geojson layer in my app. It's being loaded dynamically. Basically, I need to add marker to all geojson features so I need "position".
I have loop like this :
for (GeoJsonFeature feature : layer.getFeatures())
feature.setPolygonStyle(polygonStyle);
But I have no idea how to get coordinates from feature. I've tried this method :
private List<LatLng> getCoordinatesFromGeometry(Geometry geometry)
List<LatLng> coordinates = new ArrayList<>();
// GeoJSON geometry types:
// http://geojson.org/geojson-spec.html#geometry-objects
switch (geometry.getGeometryType())
case "Point":
coordinates.add(((GeoJsonPoint) geometry).getCoordinates());
break;
case "MultiPoint":
List<GeoJsonPoint> points = ((GeoJsonMultiPoint) geometry).getPoints();
for (GeoJsonPoint point : points)
coordinates.add(point.getCoordinates());
break;
case "LineString":
coordinates.addAll(((GeoJsonLineString) geometry).getCoordinates());
break;
case "MultiLineString":
List<GeoJsonLineString> lines =
((GeoJsonMultiLineString) geometry).getLineStrings();
for (GeoJsonLineString line : lines)
coordinates.addAll(line.getCoordinates());
break;
case "Polygon":
List<? extends List<LatLng>> lists =
((GeoJsonPolygon) geometry).getCoordinates();
for (List<LatLng> list : lists)
coordinates.addAll(list);
break;
case "MultiPolygon":
List<GeoJsonPolygon> polygons =
((GeoJsonMultiPolygon) geometry).getPolygons();
for (GeoJsonPolygon polygon : polygons)
for (List<LatLng> list : polygon.getCoordinates())
coordinates.addAll(list);
break;
return coordinates;
However it doesn't seems to work. Any help, please ?
android geojson
android geojson
edited 2 days ago
MrUpsidown
14.5k64893
14.5k64893
asked 2 days ago
Bartos
214316
214316
"But I have no idea how to get coordinates from feature. " Referring to http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/geojson/GeoJsonFeature.html aGeoJSONFeature
has thegetGeometry()
method which gives you aGeoJsonGeometry
which is one of the geometry types like a point, line, multiline etc. and you already have the code for extracting the individual coordinate points from those. So, what is the problem?
– Markus Kauppinen
2 days ago
1
I suppose you want just one marker for each feature. Then of course extracting all the coordinate points is a starting point but not enough. You need to decice how you want to decide the marker location for a feature. You could have a look at calculating the bounding box for a feature and then calculating the middle point of the bounding box. I'm not sure this is the solution, but at least something to consider.
– Markus Kauppinen
2 days ago
Of course if the GeoJSON features are quite small (in relation to expected map zoom levels) it might be enough to just pick one of the coordinate points e.g. the first one and then there's no point in anything more elaborate.
– Markus Kauppinen
2 days ago
add a comment |
"But I have no idea how to get coordinates from feature. " Referring to http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/geojson/GeoJsonFeature.html aGeoJSONFeature
has thegetGeometry()
method which gives you aGeoJsonGeometry
which is one of the geometry types like a point, line, multiline etc. and you already have the code for extracting the individual coordinate points from those. So, what is the problem?
– Markus Kauppinen
2 days ago
1
I suppose you want just one marker for each feature. Then of course extracting all the coordinate points is a starting point but not enough. You need to decice how you want to decide the marker location for a feature. You could have a look at calculating the bounding box for a feature and then calculating the middle point of the bounding box. I'm not sure this is the solution, but at least something to consider.
– Markus Kauppinen
2 days ago
Of course if the GeoJSON features are quite small (in relation to expected map zoom levels) it might be enough to just pick one of the coordinate points e.g. the first one and then there's no point in anything more elaborate.
– Markus Kauppinen
2 days ago
"But I have no idea how to get coordinates from feature. " Referring to http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/geojson/GeoJsonFeature.html a
GeoJSONFeature
has the getGeometry()
method which gives you a GeoJsonGeometry
which is one of the geometry types like a point, line, multiline etc. and you already have the code for extracting the individual coordinate points from those. So, what is the problem?– Markus Kauppinen
2 days ago
"But I have no idea how to get coordinates from feature. " Referring to http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/geojson/GeoJsonFeature.html a
GeoJSONFeature
has the getGeometry()
method which gives you a GeoJsonGeometry
which is one of the geometry types like a point, line, multiline etc. and you already have the code for extracting the individual coordinate points from those. So, what is the problem?– Markus Kauppinen
2 days ago
1
1
I suppose you want just one marker for each feature. Then of course extracting all the coordinate points is a starting point but not enough. You need to decice how you want to decide the marker location for a feature. You could have a look at calculating the bounding box for a feature and then calculating the middle point of the bounding box. I'm not sure this is the solution, but at least something to consider.
– Markus Kauppinen
2 days ago
I suppose you want just one marker for each feature. Then of course extracting all the coordinate points is a starting point but not enough. You need to decice how you want to decide the marker location for a feature. You could have a look at calculating the bounding box for a feature and then calculating the middle point of the bounding box. I'm not sure this is the solution, but at least something to consider.
– Markus Kauppinen
2 days ago
Of course if the GeoJSON features are quite small (in relation to expected map zoom levels) it might be enough to just pick one of the coordinate points e.g. the first one and then there's no point in anything more elaborate.
– Markus Kauppinen
2 days ago
Of course if the GeoJSON features are quite small (in relation to expected map zoom levels) it might be enough to just pick one of the coordinate points e.g. the first one and then there's no point in anything more elaborate.
– Markus Kauppinen
2 days ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225164%2fgetting-coordinates-from-geojson%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
"But I have no idea how to get coordinates from feature. " Referring to http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/geojson/GeoJsonFeature.html a
GeoJSONFeature
has thegetGeometry()
method which gives you aGeoJsonGeometry
which is one of the geometry types like a point, line, multiline etc. and you already have the code for extracting the individual coordinate points from those. So, what is the problem?– Markus Kauppinen
2 days ago
1
I suppose you want just one marker for each feature. Then of course extracting all the coordinate points is a starting point but not enough. You need to decice how you want to decide the marker location for a feature. You could have a look at calculating the bounding box for a feature and then calculating the middle point of the bounding box. I'm not sure this is the solution, but at least something to consider.
– Markus Kauppinen
2 days ago
Of course if the GeoJSON features are quite small (in relation to expected map zoom levels) it might be enough to just pick one of the coordinate points e.g. the first one and then there's no point in anything more elaborate.
– Markus Kauppinen
2 days ago