use of mil.nga.sf.GeometryCollection in project geopackage-android-map by ngageoint.
the class GoogleMapShapeConverter method toGeometry.
/**
* Convert a GoogleMapShape to a Geometry
*
* @param shape google map shape
* @return geometry
*/
public Geometry toGeometry(GoogleMapShape shape) {
Geometry geometry = null;
Object shapeObject = shape.getShape();
switch(shape.getGeometryType()) {
case POINT:
LatLng point = null;
switch(shape.getShapeType()) {
case LAT_LNG:
point = (LatLng) shapeObject;
break;
case MARKER_OPTIONS:
MarkerOptions markerOptions = (MarkerOptions) shapeObject;
point = markerOptions.getPosition();
break;
case MARKER:
Marker marker = (Marker) shapeObject;
point = marker.getPosition();
break;
default:
throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
}
if (point != null) {
geometry = toPoint(point);
}
break;
case LINESTRING:
case CIRCULARSTRING:
List<LatLng> lineStringPoints = null;
switch(shape.getShapeType()) {
case POLYLINE_OPTIONS:
PolylineOptions polylineOptions = (PolylineOptions) shapeObject;
lineStringPoints = polylineOptions.getPoints();
break;
case POLYLINE:
Polyline polyline = (Polyline) shapeObject;
lineStringPoints = polyline.getPoints();
break;
case POLYLINE_MARKERS:
PolylineMarkers polylineMarkers = (PolylineMarkers) shapeObject;
if (!polylineMarkers.isValid()) {
throw new GeoPackageException(PolylineMarkers.class.getSimpleName() + " is not valid to create " + shape.getGeometryType().getName());
}
if (!polylineMarkers.isDeleted()) {
lineStringPoints = getPointsFromMarkers(polylineMarkers.getMarkers());
}
break;
default:
throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
}
if (lineStringPoints != null) {
switch(shape.getGeometryType()) {
case LINESTRING:
geometry = toLineString(lineStringPoints);
break;
case CIRCULARSTRING:
geometry = toCircularString(lineStringPoints);
break;
default:
throw new GeoPackageException("Unhandled " + shape.getGeometryType().getName());
}
}
break;
case POLYGON:
List<LatLng> polygonPoints = null;
List<List<LatLng>> holePointList = null;
switch(shape.getShapeType()) {
case POLYGON_OPTIONS:
PolygonOptions polygonOptions = (PolygonOptions) shapeObject;
polygonPoints = polygonOptions.getPoints();
holePointList = polygonOptions.getHoles();
break;
case POLYGON:
com.google.android.gms.maps.model.Polygon polygon = (com.google.android.gms.maps.model.Polygon) shapeObject;
polygonPoints = polygon.getPoints();
holePointList = polygon.getHoles();
break;
case POLYGON_MARKERS:
PolygonMarkers polygonMarkers = (PolygonMarkers) shapeObject;
if (!polygonMarkers.isValid()) {
throw new GeoPackageException(PolygonMarkers.class.getSimpleName() + " is not valid to create " + shape.getGeometryType().getName());
}
if (!polygonMarkers.isDeleted()) {
polygonPoints = getPointsFromMarkers(polygonMarkers.getMarkers());
holePointList = new ArrayList<>();
for (PolygonHoleMarkers hole : polygonMarkers.getHoles()) {
if (!hole.isDeleted()) {
List<LatLng> holePoints = getPointsFromMarkers(hole.getMarkers());
holePointList.add(holePoints);
}
}
}
break;
default:
throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
}
if (polygonPoints != null) {
geometry = toPolygon(polygonPoints, holePointList);
}
break;
case MULTIPOINT:
List<LatLng> multiPoints = null;
switch(shape.getShapeType()) {
case MULTI_LAT_LNG:
MultiLatLng multiLatLng = (MultiLatLng) shapeObject;
multiPoints = multiLatLng.getLatLngs();
break;
case MULTI_MARKER:
MultiMarker multiMarker = (MultiMarker) shapeObject;
multiPoints = getPointsFromMarkers(multiMarker.getMarkers());
break;
default:
throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
}
if (multiPoints != null) {
geometry = toMultiPoint(multiPoints);
}
break;
case MULTILINESTRING:
case COMPOUNDCURVE:
switch(shape.getShapeType()) {
case MULTI_POLYLINE_OPTIONS:
MultiPolylineOptions multiPolylineOptions = (MultiPolylineOptions) shapeObject;
switch(shape.getGeometryType()) {
case MULTILINESTRING:
geometry = toMultiLineStringFromOptions(multiPolylineOptions);
break;
case COMPOUNDCURVE:
geometry = toCompoundCurveFromOptions(multiPolylineOptions);
break;
default:
throw new GeoPackageException("Unhandled " + shape.getGeometryType().getName());
}
break;
case MULTI_POLYLINE:
MultiPolyline multiPolyline = (MultiPolyline) shapeObject;
switch(shape.getGeometryType()) {
case MULTILINESTRING:
geometry = toMultiLineString(multiPolyline.getPolylines());
break;
case COMPOUNDCURVE:
geometry = toCompoundCurve(multiPolyline.getPolylines());
break;
default:
throw new GeoPackageException("Unhandled " + shape.getGeometryType().getName());
}
break;
case MULTI_POLYLINE_MARKERS:
MultiPolylineMarkers multiPolylineMarkers = (MultiPolylineMarkers) shapeObject;
if (!multiPolylineMarkers.isValid()) {
throw new GeoPackageException(MultiPolylineMarkers.class.getSimpleName() + " is not valid to create " + shape.getGeometryType().getName());
}
if (!multiPolylineMarkers.isDeleted()) {
List<List<LatLng>> multiPolylineMarkersList = new ArrayList<>();
for (PolylineMarkers polylineMarkers : multiPolylineMarkers.getPolylineMarkers()) {
if (!polylineMarkers.isDeleted()) {
multiPolylineMarkersList.add(getPointsFromMarkers(polylineMarkers.getMarkers()));
}
}
switch(shape.getGeometryType()) {
case MULTILINESTRING:
geometry = toMultiLineStringFromList(multiPolylineMarkersList);
break;
case COMPOUNDCURVE:
geometry = toCompoundCurveFromList(multiPolylineMarkersList);
break;
default:
throw new GeoPackageException("Unhandled " + shape.getGeometryType().getName());
}
}
break;
default:
throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
}
break;
case MULTIPOLYGON:
switch(shape.getShapeType()) {
case MULTI_POLYGON_OPTIONS:
MultiPolygonOptions multiPolygonOptions = (MultiPolygonOptions) shapeObject;
geometry = toMultiPolygonFromOptions(multiPolygonOptions);
break;
case MULTI_POLYGON:
mil.nga.geopackage.map.geom.MultiPolygon multiPolygon = (mil.nga.geopackage.map.geom.MultiPolygon) shapeObject;
geometry = toMultiPolygon(multiPolygon.getPolygons());
break;
case MULTI_POLYGON_MARKERS:
MultiPolygonMarkers multiPolygonMarkers = (MultiPolygonMarkers) shapeObject;
if (!multiPolygonMarkers.isValid()) {
throw new GeoPackageException(MultiPolygonMarkers.class.getSimpleName() + " is not valid to create " + shape.getGeometryType().getName());
}
if (!multiPolygonMarkers.isDeleted()) {
List<Polygon> multiPolygonMarkersList = new ArrayList<>();
for (PolygonMarkers polygonMarkers : multiPolygonMarkers.getPolygonMarkers()) {
if (!polygonMarkers.isDeleted()) {
List<LatLng> multiPolygonPoints = getPointsFromMarkers(polygonMarkers.getMarkers());
List<List<LatLng>> multiPolygonHolePoints = new ArrayList<>();
for (PolygonHoleMarkers hole : polygonMarkers.getHoles()) {
if (!hole.isDeleted()) {
List<LatLng> holePoints = getPointsFromMarkers(hole.getMarkers());
multiPolygonHolePoints.add(holePoints);
}
}
multiPolygonMarkersList.add(toPolygon(multiPolygonPoints, multiPolygonHolePoints));
}
}
geometry = createMultiPolygon(multiPolygonMarkersList);
}
break;
default:
throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
}
break;
case POLYHEDRALSURFACE:
case TIN:
case TRIANGLE:
throw new GeoPackageException("Unsupported GeoPackage type: " + shape.getGeometryType());
case GEOMETRYCOLLECTION:
@SuppressWarnings("unchecked") List<GoogleMapShape> shapeList = (List<GoogleMapShape>) shapeObject;
GeometryCollection<Geometry> geometryCollection = new GeometryCollection<>(false, false);
for (GoogleMapShape shapeListItem : shapeList) {
Geometry subGeometry = toGeometry(shapeListItem);
if (subGeometry != null) {
geometryCollection.addGeometry(subGeometry);
}
}
if (geometryCollection.numGeometries() > 0) {
geometry = geometryCollection;
}
break;
default:
}
return geometry;
}
Aggregations