Search in sources :

Example 1 with Point

use of mil.nga.sf.Point in project geopackage-android-map by ngageoint.

the class GoogleMapShapeConverter method toPolygon.

/**
 * Convert a list of {@link LatLng} and list of hole list {@link LatLng} to
 * a {@link Polygon}
 *
 * @param latLngs lat lngs
 * @param holes   list of holes
 * @param hasZ    has z flag
 * @param hasM    has m flag
 * @return polygon
 */
public Polygon toPolygon(List<LatLng> latLngs, List<List<LatLng>> holes, boolean hasZ, boolean hasM) {
    Polygon polygon = new Polygon(hasZ, hasM);
    // Close the ring if needed and determine orientation
    closePolygonRing(latLngs);
    PolygonOrientation ringOrientation = getOrientation(latLngs);
    // Add the polygon points
    LineString polygonLineString = new LineString(hasZ, hasM);
    for (LatLng latLng : latLngs) {
        Point point = toPoint(latLng);
        // Add exterior in desired orientation order
        if (exteriorOrientation == null || exteriorOrientation == ringOrientation) {
            polygonLineString.addPoint(point);
        } else {
            polygonLineString.getPoints().add(0, point);
        }
    }
    polygon.addRing(polygonLineString);
    // Add the holes
    if (holes != null) {
        for (List<LatLng> hole : holes) {
            // Close the hole if needed and determine orientation
            closePolygonRing(hole);
            PolygonOrientation ringHoleOrientation = getOrientation(hole);
            LineString holeLineString = new LineString(hasZ, hasM);
            for (LatLng latLng : hole) {
                Point point = toPoint(latLng);
                // Add holes in desired orientation order
                if (holeOrientation == null || holeOrientation == ringHoleOrientation) {
                    holeLineString.addPoint(point);
                } else {
                    holeLineString.getPoints().add(0, point);
                }
            }
            polygon.addRing(holeLineString);
        }
    }
    return polygon;
}
Also used : LineString(mil.nga.sf.LineString) MultiLineString(mil.nga.sf.MultiLineString) LatLng(com.google.android.gms.maps.model.LatLng) MultiPoint(mil.nga.sf.MultiPoint) Point(mil.nga.sf.Point) MultiPolygon(mil.nga.sf.MultiPolygon) CurvePolygon(mil.nga.sf.CurvePolygon) Polygon(mil.nga.sf.Polygon)

Example 2 with Point

use of mil.nga.sf.Point in project geopackage-android-map by ngageoint.

the class GoogleMapShapeConverter method toCurvePolygon.

/**
 * Convert a {@link CurvePolygon} to a {@link PolygonOptions}
 *
 * @param curvePolygon curve polygon
 * @return polygon options
 * @since 1.4.1
 */
public PolygonOptions toCurvePolygon(CurvePolygon<Curve> curvePolygon) {
    PolygonOptions polygonOptions = new PolygonOptions();
    List<Curve> rings = curvePolygon.getRings();
    if (!rings.isEmpty()) {
        Double z = null;
        // Add the polygon points
        Curve curve = rings.get(0);
        if (curve instanceof CompoundCurve) {
            CompoundCurve compoundCurve = (CompoundCurve) curve;
            for (LineString lineString : compoundCurve.getLineStrings()) {
                // Try to simplify the number of points in the compound curve
                List<Point> points = simplifyPoints(lineString.getPoints());
                for (Point point : points) {
                    LatLng latLng = toLatLng(point);
                    polygonOptions.add(latLng);
                    if (point.hasZ()) {
                        z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
                    }
                }
            }
        } else if (curve instanceof LineString) {
            LineString lineString = (LineString) curve;
            // Try to simplify the number of points in the curve
            List<Point> points = simplifyPoints(lineString.getPoints());
            for (Point point : points) {
                LatLng latLng = toLatLng(point);
                polygonOptions.add(latLng);
                if (point.hasZ()) {
                    z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
                }
            }
        } else {
            throw new GeoPackageException("Unsupported Curve Type: " + curve.getClass().getSimpleName());
        }
        // Add the holes
        for (int i = 1; i < rings.size(); i++) {
            Curve hole = rings.get(i);
            List<LatLng> holeLatLngs = new ArrayList<>();
            if (hole instanceof CompoundCurve) {
                CompoundCurve holeCompoundCurve = (CompoundCurve) hole;
                for (LineString holeLineString : holeCompoundCurve.getLineStrings()) {
                    // Try to simplify the number of points in the hole
                    List<Point> holePoints = simplifyPoints(holeLineString.getPoints());
                    for (Point point : holePoints) {
                        LatLng latLng = toLatLng(point);
                        holeLatLngs.add(latLng);
                        if (point.hasZ()) {
                            z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
                        }
                    }
                }
            } else if (hole instanceof LineString) {
                LineString holeLineString = (LineString) hole;
                // Try to simplify the number of points in the hole
                List<Point> holePoints = simplifyPoints(holeLineString.getPoints());
                for (Point point : holePoints) {
                    LatLng latLng = toLatLng(point);
                    holeLatLngs.add(latLng);
                    if (point.hasZ()) {
                        z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
                    }
                }
            } else {
                throw new GeoPackageException("Unsupported Curve Hole Type: " + hole.getClass().getSimpleName());
            }
            polygonOptions.addHole(holeLatLngs);
        }
        if (curvePolygon.hasZ() && z != null) {
            polygonOptions.zIndex(z.floatValue());
        }
    }
    return polygonOptions;
}
Also used : CompoundCurve(mil.nga.sf.CompoundCurve) PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) Curve(mil.nga.sf.Curve) CompoundCurve(mil.nga.sf.CompoundCurve) ArrayList(java.util.ArrayList) MultiPoint(mil.nga.sf.MultiPoint) Point(mil.nga.sf.Point) MultiPoint(mil.nga.sf.MultiPoint) Point(mil.nga.sf.Point) LineString(mil.nga.sf.LineString) MultiLineString(mil.nga.sf.MultiLineString) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.google.android.gms.maps.model.LatLng) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Example 3 with Point

use of mil.nga.sf.Point in project geopackage-android-map by ngageoint.

the class GoogleMapShapeConverter method addToMap.

/**
 * Convert a {@link Geometry} to a Map shape and add it
 *
 * @param map      google map
 * @param geometry geometry
 * @return google map shape
 */
@SuppressWarnings("unchecked")
public GoogleMapShape addToMap(GoogleMap map, Geometry geometry) {
    GoogleMapShape shape = null;
    GeometryType geometryType = geometry.getGeometryType();
    switch(geometryType) {
        case POINT:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MARKER, addLatLngToMap(map, toLatLng((Point) geometry)));
            break;
        case LINESTRING:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYLINE, addPolylineToMap(map, toPolyline((LineString) geometry)));
            break;
        case POLYGON:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYGON, addPolygonToMap(map, toPolygon((Polygon) geometry)));
            break;
        case MULTIPOINT:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_MARKER, addLatLngsToMap(map, toLatLngs((MultiPoint) geometry)));
            break;
        case MULTILINESTRING:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYLINE, addPolylinesToMap(map, toPolylines((MultiLineString) geometry)));
            break;
        case MULTIPOLYGON:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYGON, addPolygonsToMap(map, toPolygons((MultiPolygon) geometry)));
            break;
        case CIRCULARSTRING:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYLINE, addPolylineToMap(map, toPolyline((CircularString) geometry)));
            break;
        case COMPOUNDCURVE:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYLINE, addPolylinesToMap(map, toPolylines((CompoundCurve) geometry)));
            break;
        case CURVEPOLYGON:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYGON, addPolygonToMap(map, toCurvePolygon((CurvePolygon<Curve>) geometry)));
            break;
        case POLYHEDRALSURFACE:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYGON, addPolygonsToMap(map, toPolygons((PolyhedralSurface) geometry)));
            break;
        case TIN:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYGON, addPolygonsToMap(map, toPolygons((TIN) geometry)));
            break;
        case TRIANGLE:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYGON, addPolygonToMap(map, toPolygon((Triangle) geometry)));
            break;
        case GEOMETRYCOLLECTION:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.COLLECTION, addToMap(map, (GeometryCollection<Geometry>) geometry));
            break;
        default:
            throw new GeoPackageException("Unsupported Geometry Type: " + geometryType.getName());
    }
    return shape;
}
Also used : MultiPoint(mil.nga.sf.MultiPoint) MultiLineString(mil.nga.sf.MultiLineString) CompoundCurve(mil.nga.sf.CompoundCurve) CircularString(mil.nga.sf.CircularString) Triangle(mil.nga.sf.Triangle) CurvePolygon(mil.nga.sf.CurvePolygon) MultiPoint(mil.nga.sf.MultiPoint) Point(mil.nga.sf.Point) PolyhedralSurface(mil.nga.sf.PolyhedralSurface) Geometry(mil.nga.sf.Geometry) GeometryType(mil.nga.sf.GeometryType) LineString(mil.nga.sf.LineString) MultiLineString(mil.nga.sf.MultiLineString) MultiPolygon(mil.nga.sf.MultiPolygon) TIN(mil.nga.sf.TIN) MultiPolygon(mil.nga.sf.MultiPolygon) CurvePolygon(mil.nga.sf.CurvePolygon) Polygon(mil.nga.sf.Polygon) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Example 4 with Point

use of mil.nga.sf.Point in project geopackage-android-map by ngageoint.

the class GoogleMapShapeConverter method toMultiPoint.

/**
 * Convert a {@link MultiLatLng} to a {@link MultiPoint}
 *
 * @param latLngs lat lngs
 * @param hasZ    has z flag
 * @param hasM    has m flag
 * @return multi point
 */
public MultiPoint toMultiPoint(List<LatLng> latLngs, boolean hasZ, boolean hasM) {
    MultiPoint multiPoint = new MultiPoint(hasZ, hasM);
    for (LatLng latLng : latLngs) {
        Point point = toPoint(latLng);
        multiPoint.addPoint(point);
    }
    return multiPoint;
}
Also used : MultiPoint(mil.nga.sf.MultiPoint) LatLng(com.google.android.gms.maps.model.LatLng) MultiPoint(mil.nga.sf.MultiPoint) Point(mil.nga.sf.Point)

Example 5 with Point

use of mil.nga.sf.Point in project geopackage-android-map by ngageoint.

the class TestUtils method addRowsToFeatureTable.

/**
 * Add rows to the feature table
 *
 * @param geoPackage
 * @param geometryColumns
 * @param table
 * @param numRows
 * @param hasZ
 * @param hasM
 * @param allowEmptyFeatures
 * @throws SQLException
 */
public static void addRowsToFeatureTable(GeoPackage geoPackage, GeometryColumns geometryColumns, FeatureTable table, int numRows, boolean hasZ, boolean hasM, boolean allowEmptyFeatures) throws SQLException {
    FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
    for (int i = 0; i < numRows; i++) {
        FeatureRow newRow = dao.newRow();
        for (FeatureColumn column : table.getColumns()) {
            if (!column.isPrimaryKey()) {
                // Leave nullable columns null 20% of the time
                if (!column.isNotNull()) {
                    if (allowEmptyFeatures && Math.random() < .2) {
                        continue;
                    }
                }
                if (column.isGeometry()) {
                    Geometry geometry = null;
                    switch(column.getGeometryType()) {
                        case POINT:
                            geometry = createPoint(hasZ, hasM);
                            break;
                        case LINESTRING:
                            geometry = createLineString(hasZ, hasM, false);
                            break;
                        case POLYGON:
                            geometry = createPolygon(hasZ, hasM);
                            break;
                        default:
                            throw new UnsupportedOperationException("Not implemented for geometry type: " + column.getGeometryType());
                    }
                    GeoPackageGeometryData geometryData = new GeoPackageGeometryData(geometryColumns.getSrsId());
                    geometryData.setGeometry(geometry);
                    newRow.setGeometry(geometryData);
                } else {
                    Object value = null;
                    switch(column.getDataType()) {
                        case TEXT:
                            String text = UUID.randomUUID().toString();
                            if (column.getMax() != null && text.length() > column.getMax()) {
                                text = text.substring(0, column.getMax().intValue());
                            }
                            value = text;
                            break;
                        case REAL:
                        case DOUBLE:
                            value = Math.random() * 5000.0;
                            break;
                        case BOOLEAN:
                            value = Math.random() < .5 ? false : true;
                            break;
                        case INTEGER:
                        case INT:
                            value = (int) (Math.random() * 500);
                            break;
                        case BLOB:
                            byte[] blob = UUID.randomUUID().toString().getBytes();
                            if (column.getMax() != null && blob.length > column.getMax()) {
                                byte[] blobLimited = new byte[column.getMax().intValue()];
                                ByteBuffer.wrap(blob, 0, column.getMax().intValue()).get(blobLimited);
                                blob = blobLimited;
                            }
                            value = blob;
                            break;
                        default:
                            throw new UnsupportedOperationException("Not implemented for data type: " + column.getDataType());
                    }
                    newRow.setValue(column.getName(), value);
                }
            }
        }
        dao.create(newRow);
    }
}
Also used : Geometry(mil.nga.sf.Geometry) GeoPackageGeometryData(mil.nga.geopackage.geom.GeoPackageGeometryData) FeatureRow(mil.nga.geopackage.features.user.FeatureRow) FeatureColumn(mil.nga.geopackage.features.user.FeatureColumn) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) LineString(mil.nga.sf.LineString) Point(mil.nga.sf.Point)

Aggregations

Point (mil.nga.sf.Point)16 MultiPoint (mil.nga.sf.MultiPoint)11 LatLng (com.google.android.gms.maps.model.LatLng)9 LineString (mil.nga.sf.LineString)5 MultiLineString (mil.nga.sf.MultiLineString)4 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)2 ArrayList (java.util.ArrayList)2 GeoPackageException (mil.nga.geopackage.GeoPackageException)2 FeatureRow (mil.nga.geopackage.features.user.FeatureRow)2 GeoPackageGeometryData (mil.nga.geopackage.geom.GeoPackageGeometryData)2 CompoundCurve (mil.nga.sf.CompoundCurve)2 CurvePolygon (mil.nga.sf.CurvePolygon)2 Geometry (mil.nga.sf.Geometry)2 MultiPolygon (mil.nga.sf.MultiPolygon)2 Polygon (mil.nga.sf.Polygon)2 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)1 List (java.util.List)1 BoundingBox (mil.nga.geopackage.BoundingBox)1 DataColumnsDao (mil.nga.geopackage.extension.schema.columns.DataColumnsDao)1 FeatureIndexResults (mil.nga.geopackage.features.index.FeatureIndexResults)1