Search in sources :

Example 1 with LineString

use of mil.nga.sf.LineString 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 LineString

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

the class GoogleMapShapeConverter method toCompoundCurveWithOptions.

/**
 * Convert a {@link MultiPolylineOptions} to a {@link CompoundCurve}
 *
 * @param multiPolylineOptions multi polyline options
 * @param hasZ                 has z flag
 * @param hasM                 has m flag
 * @return compound curve
 */
public CompoundCurve toCompoundCurveWithOptions(MultiPolylineOptions multiPolylineOptions, boolean hasZ, boolean hasM) {
    CompoundCurve compoundCurve = new CompoundCurve(hasZ, hasM);
    for (PolylineOptions polyline : multiPolylineOptions.getPolylineOptions()) {
        LineString lineString = toLineString(polyline);
        compoundCurve.addLineString(lineString);
    }
    return compoundCurve;
}
Also used : CompoundCurve(mil.nga.sf.CompoundCurve) LineString(mil.nga.sf.LineString) MultiLineString(mil.nga.sf.MultiLineString) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Example 3 with LineString

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

the class GoogleMapShapeConverter method toLineString.

/**
 * Convert a list of {@link LatLng} to a {@link LineString}
 *
 * @param latLngs lat lngs
 * @param hasZ    has z flag
 * @param hasM    has m flag
 * @return line string
 */
public LineString toLineString(List<LatLng> latLngs, boolean hasZ, boolean hasM) {
    LineString lineString = new LineString(hasZ, hasM);
    populateLineString(lineString, latLngs);
    return lineString;
}
Also used : LineString(mil.nga.sf.LineString) MultiLineString(mil.nga.sf.MultiLineString)

Example 4 with LineString

use of mil.nga.sf.LineString 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 5 with LineString

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

the class GoogleMapShapeConverter method toCompoundCurve.

/**
 * Convert a list of {@link Polyline} to a {@link CompoundCurve}
 *
 * @param polylineList polyline list
 * @param hasZ         has z flag
 * @param hasM         has m flag
 * @return compound curve
 */
public CompoundCurve toCompoundCurve(List<Polyline> polylineList, boolean hasZ, boolean hasM) {
    CompoundCurve compoundCurve = new CompoundCurve(hasZ, hasM);
    for (Polyline polyline : polylineList) {
        LineString lineString = toLineString(polyline);
        compoundCurve.addLineString(lineString);
    }
    return compoundCurve;
}
Also used : CompoundCurve(mil.nga.sf.CompoundCurve) LineString(mil.nga.sf.LineString) MultiLineString(mil.nga.sf.MultiLineString) Polyline(com.google.android.gms.maps.model.Polyline)

Aggregations

LineString (mil.nga.sf.LineString)58 Point (mil.nga.sf.Point)37 MultiLineString (mil.nga.sf.MultiLineString)34 Polygon (mil.nga.sf.Polygon)19 ArrayList (java.util.ArrayList)16 MultiPoint (mil.nga.sf.MultiPoint)13 Test (org.junit.Test)10 CompoundCurve (mil.nga.sf.CompoundCurve)9 Geometry (mil.nga.sf.Geometry)7 MultiPolygon (mil.nga.sf.MultiPolygon)7 LatLng (com.google.android.gms.maps.model.LatLng)6 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)6 CurvePolygon (mil.nga.sf.CurvePolygon)5 CircularString (mil.nga.sf.CircularString)4 GeoPackageException (mil.nga.geopackage.GeoPackageException)3 FeatureRow (mil.nga.geopackage.features.user.FeatureRow)3 GeoPackageGeometryData (mil.nga.geopackage.geom.GeoPackageGeometryData)3 GeometryType (mil.nga.sf.GeometryType)3 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)2 Polyline (com.google.android.gms.maps.model.Polyline)2