mil.nga.sf.LineString Java Examples

The following examples show how to use mil.nga.sf.LineString. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultFeatureTiles.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Get the area of the polygon
 *
 * @param simplifyTolerance
 *            simplify tolerance in meters
 * @param boundingBox
 * @param transform
 * @param lineString
 */
private Area getArea(double simplifyTolerance, BoundingBox boundingBox,
		ProjectionTransform transform, Polygon polygon) {

	Area area = null;

	for (LineString ring : polygon.getRings()) {

		Path2D path = getPath(simplifyTolerance, boundingBox, transform,
				ring);
		Area ringArea = new Area(path);

		if (area == null) {
			area = ringArea;
		} else {
			area.subtract(ringArea);
		}

	}

	return area;
}
 
Example #2
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Test the MultiLineString conversion
 * 
 * @param converter
 * @param multiLineString
 */
private static void convertMultiLineString(
		GoogleMapShapeConverter converter, MultiLineString multiLineString) {

	MultiPolylineOptions polylines = converter.toPolylines(multiLineString);
	TestCase.assertNotNull(polylines);
	TestCase.assertFalse(polylines.getPolylineOptions().isEmpty());

	List<LineString> lineStrings = multiLineString.getLineStrings();
	compareLineStringsAndPolylines(converter, lineStrings,
			polylines.getPolylineOptions());

	MultiLineString multiLineString2 = converter
			.toMultiLineStringFromOptions(polylines);
	compareLineStrings(lineStrings, multiLineString2.getLineStrings());
}
 
Example #3
Source File: TestUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Create a random line string
 *
 * @param hasZ
 * @param hasM
 * @param ring
 * @return
 */
public static LineString createLineString(boolean hasZ, boolean hasM,
                                          boolean ring) {

    LineString lineString = new LineString(hasZ, hasM);

    int numPoints = 2 + ((int) (Math.random() * 9));

    for (int i = 0; i < numPoints; i++) {
        lineString.addPoint(createPoint(hasZ, hasM));
    }

    if (ring) {
        lineString.addPoint(lineString.getPoints().get(0));
    }

    return lineString;
}
 
Example #4
Source File: GeoPackagePerformance.java    From geopackage-java with MIT License 6 votes vote down vote up
private static Geometry createGeometry() {

		Polygon polygon = new Polygon();
		LineString ring = new LineString();
		ring.addPoint(new Point(-104.802246, 39.720343));
		ring.addPoint(new Point(-104.802246, 39.719753));
		ring.addPoint(new Point(-104.802183, 39.719754));
		ring.addPoint(new Point(-104.802184, 39.719719));
		ring.addPoint(new Point(-104.802138, 39.719694));
		ring.addPoint(new Point(-104.802097, 39.719691));
		ring.addPoint(new Point(-104.802096, 39.719648));
		ring.addPoint(new Point(-104.801646, 39.719648));
		ring.addPoint(new Point(-104.801644, 39.719722));
		ring.addPoint(new Point(-104.801550, 39.719723));
		ring.addPoint(new Point(-104.801549, 39.720207));
		ring.addPoint(new Point(-104.801648, 39.720207));
		ring.addPoint(new Point(-104.801648, 39.720341));
		ring.addPoint(new Point(-104.802246, 39.720343));
		polygon.addRing(ring);

		return polygon;
	}
 
Example #5
Source File: TestUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Create a random line string
 * 
 * @param hasZ
 * @param hasM
 * @param ring
 * @return line string
 */
public static LineString createLineString(boolean hasZ, boolean hasM,
		boolean ring) {

	LineString lineString = new LineString(hasZ, hasM);

	int numPoints = 2 + ((int) (Math.random() * 9));

	for (int i = 0; i < numPoints; i++) {
		lineString.addPoint(createPoint(hasZ, hasM));
	}

	if (ring) {
		lineString.addPoint(lineString.getPoints().get(0));
	}

	return lineString;
}
 
Example #6
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Compare Polygon with Map Polygon
 *
    * @param converter
 * @param polygon
 * @param polygon2
 */
private static void comparePolygonAndMapPolygon(GoogleMapShapeConverter converter,
           Polygon polygon,
		PolygonOptions polygon2) {
	List<LineString> rings = polygon.getRings();
	List<LatLng> points = polygon2.getPoints();
	List<List<LatLng>> holes = polygon2.getHoles();

	TestCase.assertEquals(polygon.numRings(), 1 + holes.size());

	LineString polygonRing = rings.get(0);
	compareLineStringAndLatLngs(converter, polygonRing, points);

	for (int i = 1; i < rings.size(); i++) {
		LineString ring = rings.get(i);
		List<LatLng> hole = holes.get(i - 1);
		compareLineStringAndLatLngs(converter, ring, hole);
	}
}
 
Example #7
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Test the CompoundCurve conversion
 * 
 * @param converter
 * @param compoundCurve
 */
private static void convertCompoundCurve(GoogleMapShapeConverter converter,
		CompoundCurve compoundCurve) {

	MultiPolylineOptions polylines = converter.toPolylines(compoundCurve);
	TestCase.assertNotNull(polylines);
	TestCase.assertFalse(polylines.getPolylineOptions().isEmpty());

	List<LineString> lineStrings = compoundCurve.getLineStrings();
	compareLineStringsAndPolylines(converter, lineStrings,
			polylines.getPolylineOptions());

	CompoundCurve compoundCurve2 = converter
			.toCompoundCurveWithOptions(polylines);
	compareLineStrings(lineStrings, compoundCurve2.getLineStrings());
}
 
Example #8
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Convert a {@link LineString} to a {@link PolylineOptions}
 *
 * @param lineString line string
 * @return polyline options
 */
public PolylineOptions toPolyline(LineString lineString) {

    PolylineOptions polylineOptions = new PolylineOptions();
    Double z = null;

    // Try to simplify the number of points in the line string
    List<Point> points = simplifyPoints(lineString.getPoints());

    for (Point point : points) {
        LatLng latLng = toLatLng(point);
        polylineOptions.add(latLng);
        if (point.hasZ()) {
            z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
        }
    }

    if (lineString.hasZ() && z != null) {
        polylineOptions.zIndex(z.floatValue());
    }

    return polylineOptions;
}
 
Example #9
Source File: DefaultFeatureTiles.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Add the linestring to the path
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param boundingBox       bounding box
 * @param transform         projection transform
 * @param path              path
 * @param lineString        line string
 */
private void addLineString(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Path path, LineString lineString) {

    List<Point> points = lineString.getPoints();

    if (points.size() >= 2) {

        // Try to simplify the number of points in the LineString
        points = simplifyPoints(simplifyTolerance, points);

        for (int i = 0; i < points.size(); i++) {
            Point point = points.get(i);
            Point webMercatorPoint = transform.transform(point);
            float x = TileBoundingBoxUtils.getXPixel(tileWidth, boundingBox,
                    webMercatorPoint.getX());
            float y = TileBoundingBoxUtils.getYPixel(tileHeight, boundingBox,
                    webMercatorPoint.getY());
            if (i == 0) {
                path.moveTo(x, y);
            } else {
                path.lineTo(x, y);
            }
        }
    }
}
 
Example #10
Source File: DefaultFeatureTiles.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Add the polygon on the canvas
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param boundingBox       bounding box
 * @param transform         projection transform
 * @param path              path
 * @param polygon           polygon
 */
private void addPolygon(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Path path, Polygon polygon) {
    List<LineString> rings = polygon.getRings();
    if (!rings.isEmpty()) {

        // Add the polygon points
        LineString polygonLineString = rings.get(0);
        List<Point> polygonPoints = polygonLineString.getPoints();
        if (polygonPoints.size() >= 2) {
            addRing(simplifyTolerance, boundingBox, transform, path, polygonPoints);

            // Add the holes
            for (int i = 1; i < rings.size(); i++) {
                LineString holeLineString = rings.get(i);
                List<Point> holePoints = holeLineString.getPoints();
                if (holePoints.size() >= 2) {
                    addRing(simplifyTolerance, boundingBox, transform, path, holePoints);
                }
            }
        }
    }
}
 
Example #11
Source File: GeoPackagePerformance.java    From geopackage-android with MIT License 6 votes vote down vote up
private static Geometry createGeometry() {

        Polygon polygon = new Polygon();
        LineString ring = new LineString();
        ring.addPoint(new Point(-104.802246, 39.720343));
        ring.addPoint(new Point(-104.802246, 39.719753));
        ring.addPoint(new Point(-104.802183, 39.719754));
        ring.addPoint(new Point(-104.802184, 39.719719));
        ring.addPoint(new Point(-104.802138, 39.719694));
        ring.addPoint(new Point(-104.802097, 39.719691));
        ring.addPoint(new Point(-104.802096, 39.719648));
        ring.addPoint(new Point(-104.801646, 39.719648));
        ring.addPoint(new Point(-104.801644, 39.719722));
        ring.addPoint(new Point(-104.801550, 39.719723));
        ring.addPoint(new Point(-104.801549, 39.720207));
        ring.addPoint(new Point(-104.801648, 39.720207));
        ring.addPoint(new Point(-104.801648, 39.720341));
        ring.addPoint(new Point(-104.802246, 39.720343));
        polygon.addRing(ring);

        return polygon;
    }
 
Example #12
Source File: TestUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Create a random line string
 *
 * @param hasZ
 * @param hasM
 * @param ring
 * @return
 */
public static LineString createLineString(boolean hasZ, boolean hasM,
                                          boolean ring) {

    LineString lineString = new LineString(hasZ, hasM);

    int numPoints = 2 + ((int) (Math.random() * 9));

    for (int i = 0; i < numPoints; i++) {
        lineString.addPoint(createPoint(hasZ, hasM));
    }

    if (ring) {
        lineString.addPoint(lineString.getPoints().get(0));
    }

    return lineString;
}
 
Example #13
Source File: FeatureTileUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
public static long insertPolygon(FeatureDao featureDao, double[][]... points) {
    FeatureRow featureRow = featureDao.newRow();
    GeoPackageGeometryData geomData = new GeoPackageGeometryData(
            ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
    Polygon polygon = new Polygon(false, false);
    for (double[][] ring : points) {
        LineString lineString = getLineString(ring);
        polygon.addRing(lineString);
    }
    geomData.setGeometry(polygon);
    featureRow.setGeometry(geomData);
    return featureDao.insert(featureRow);
}
 
Example #14
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Compare two lists of line strings
 * 
 * @param lineStrings
 * @param lineStrings2
 */
private static void compareLineStrings(List<LineString> lineStrings,
		List<LineString> lineStrings2) {

	TestCase.assertEquals(lineStrings.size(), lineStrings2.size());
	for (int i = 0; i < lineStrings.size(); i++) {
		compareLineStrings(lineStrings.get(i), lineStrings2.get(i));
	}

}
 
Example #15
Source File: GeoPackageGeometryDataUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Compare the two line strings for equality
 * 
 * @param expected
 * @param actual
 * @parma delta
 */
private static void compareLineString(LineString expected,
		LineString actual, double delta) {

	compareBaseGeometryAttributes(expected, actual);
	TestCase.assertEquals(expected.numPoints(), actual.numPoints());
	for (int i = 0; i < expected.numPoints(); i++) {
		comparePoint(expected.getPoints().get(i),
				actual.getPoints().get(i), delta);
	}
}
 
Example #16
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a list of List<LatLng> to a {@link CompoundCurve}
 *
 * @param polylineList polyline list
 * @param hasZ         has z flag
 * @param hasM         has m flag
 * @return compound curve
 */
public CompoundCurve toCompoundCurveFromList(
        List<List<LatLng>> polylineList, boolean hasZ, boolean hasM) {

    CompoundCurve compoundCurve = new CompoundCurve(hasZ, hasM);

    for (List<LatLng> polyline : polylineList) {
        LineString lineString = toLineString(polyline);
        compoundCurve.addLineString(lineString);
    }

    return compoundCurve;
}
 
Example #17
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a list of {@link Polyline} to a {@link MultiLineString}
 *
 * @param polylineList polyline list
 * @param hasZ         has z flag
 * @param hasM         has m flag
 * @return multi line string
 */
public MultiLineString toMultiLineString(List<Polyline> polylineList,
                                         boolean hasZ, boolean hasM) {

    MultiLineString multiLineString = new MultiLineString(hasZ, hasM);

    for (Polyline polyline : polylineList) {
        LineString lineString = toLineString(polyline);
        multiLineString.addLineString(lineString);
    }

    return multiLineString;
}
 
Example #18
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Compare two Polygons
 * 
 * @param polygon
 * @param polygon2
 */
private static void comparePolygons(Polygon polygon, Polygon polygon2) {
	List<LineString> rings = polygon.getRings();
	List<LineString> rings2 = polygon2.getRings();

	TestCase.assertEquals(polygon.numRings(), polygon2.numRings());

	for (int i = 0; i < polygon.numRings(); i++) {
		compareLineStrings(rings.get(i), rings2.get(i));
	}
}
 
Example #19
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a {@link MultiLineString} to a {@link MultiPolylineOptions}
 *
 * @param multiLineString multi line string
 * @return multi polyline options
 */
public MultiPolylineOptions toPolylines(MultiLineString multiLineString) {

    MultiPolylineOptions polylines = new MultiPolylineOptions();

    for (LineString lineString : multiLineString.getLineStrings()) {
        PolylineOptions polyline = toPolyline(lineString);
        polylines.add(polyline);
    }

    return polylines;
}
 
Example #20
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a list of {@link LatLng} to a {@link LineString}
 *
 * @param lineString line string
 * @param latLngs    lat lngs
 */
public void populateLineString(LineString lineString, List<LatLng> latLngs) {

    for (LatLng latLng : latLngs) {
        Point point = toPoint(latLng, lineString.hasZ(), lineString.hasM());
        lineString.addPoint(point);
    }
}
 
Example #21
Source File: FeatureTileUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
private static LineString getLineString(double[][] points) {
	LineString lineString = new LineString(false, false);
	for (int i = 0; i < points.length; i++) {
		Point point = new Point(false, false, points[i][0], points[i][1]);
		lineString.addPoint(point);
	}
	return lineString;
}
 
Example #22
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Compare list of line strings with list of polylines
 *
    * @param converter
 * @param lineStrings
 * @param polylines
 */
private static void compareLineStringsAndPolylines(
           GoogleMapShapeConverter converter,
		List<LineString> lineStrings, List<PolylineOptions> polylines) {

	TestCase.assertEquals(lineStrings.size(), polylines.size());
	for (int i = 0; i < lineStrings.size(); i++) {
		compareLineStringAndPolyline(converter, lineStrings.get(i), polylines.get(i));
	}

}
 
Example #23
Source File: FeatureUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Validate Line String
 * 
 * @param topGeometry
 * @param lineString
 */
private static void validateLineString(Geometry topGeometry,
		LineString lineString) {

	TestCase.assertEquals(GeometryType.LINESTRING,
			lineString.getGeometryType());

	validateZAndM(topGeometry, lineString);

	for (Point point : lineString.getPoints()) {
		validatePoint(topGeometry, point);
	}

}
 
Example #24
Source File: DefaultFeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the path of the line string
 *
 * @param simplifyTolerance
 *            simplify tolerance in meters
 * @param boundingBox
 * @param transform
 * @param lineString
 */
private Path2D getPath(double simplifyTolerance, BoundingBox boundingBox,
		ProjectionTransform transform, LineString lineString) {

	Path2D path = null;

	// Try to simplify the number of points in the LineString
	List<Point> lineStringPoints = simplifyPoints(simplifyTolerance,
			lineString.getPoints());

	for (Point point : lineStringPoints) {

		Point projectedPoint = transform.transform(point);

		float x = TileBoundingBoxUtils.getXPixel(tileWidth, boundingBox,
				projectedPoint.getX());
		float y = TileBoundingBoxUtils.getYPixel(tileHeight, boundingBox,
				projectedPoint.getY());

		if (path == null) {
			path = new Path2D.Double();
			path.moveTo(x, y);
		} else {
			path.lineTo(x, y);
		}

	}

	return path;
}
 
Example #25
Source File: FeatureUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Validate Line String
 *
 * @param topGeometry
 * @param lineString
 */
private static void validateLineString(Geometry topGeometry,
                                       LineString lineString) {

    TestCase.assertEquals(GeometryType.LINESTRING,
            lineString.getGeometryType());

    validateZAndM(topGeometry, lineString);

    for (Point point : lineString.getPoints()) {
        validatePoint(topGeometry, point);
    }

}
 
Example #26
Source File: MapUtils.java    From mage-android with Apache License 2.0 5 votes vote down vote up
public static boolean polygonHasKinks(Polygon polygon) {
    for (LineString line1 : polygon.getRings()) {
        Point lastPoint = line1.getPoints().get(line1.numPoints() - 1);
        for (LineString line2 : polygon.getRings()) {
            for (int i = 0; i < line1.numPoints() - 1; i++) {
                Point point1 = line1.getPoints().get(i);
                Point nextPoint1 = line1.getPoints().get(i + 1);
                for (int k = i; k < line2.numPoints() - 1; k++) {
                    Point point2 = line2.getPoints().get(k);
                    Point nextPoint2 = line2.getPoints().get(k + 1);
                    if (line1 != line2) {
                        continue;
                    }

                    if (Math.abs(i - k) == 1) {
                        continue;
                    }

                    if (i == 0 && k == line1.numPoints() - 2 && point1.getX() == lastPoint.getX() && point1.getY() == lastPoint.getY()) {
                        continue;
                    }

                    boolean intersects = intersects(point1, nextPoint1, point2, nextPoint2);

                    if (intersects) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
 
Example #27
Source File: FeatureUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Validate Multi Line String
 *
 * @param topGeometry
 * @param multiLineString
 */
private static void validateMultiLineString(Geometry topGeometry,
                                            MultiLineString multiLineString) {

    TestCase.assertEquals(GeometryType.MULTILINESTRING,
            multiLineString.getGeometryType());

    validateZAndM(topGeometry, multiLineString);

    for (LineString lineString : multiLineString.getLineStrings()) {
        validateLineString(topGeometry, lineString);
    }

}
 
Example #28
Source File: FeatureTileUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
private static LineString getLineString(double[][] points) {
    LineString lineString = new LineString(false, false);
    for (int i = 0; i < points.length; i++) {
        Point point = new Point(false, false, points[i][0], points[i][1]);
        lineString.addPoint(point);
    }
    return lineString;
}
 
Example #29
Source File: GeoPackageGeometryDataUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Compare the two line strings for equality
 *
 * @param expected
 * @param actual
 * @parma delta
 */
private static void compareLineString(LineString expected,
                                      LineString actual, double delta) {

    compareBaseGeometryAttributes(expected, actual);
    TestCase.assertEquals(expected.numPoints(), actual.numPoints());
    for (int i = 0; i < expected.numPoints(); i++) {
        comparePoint(expected.getPoints().get(i),
                actual.getPoints().get(i), delta);
    }
}
 
Example #30
Source File: FeatureTileUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
public static long insertLine(FeatureDao featureDao, double[][] points) {
    FeatureRow featureRow = featureDao.newRow();
    GeoPackageGeometryData geomData = new GeoPackageGeometryData(
            ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
    LineString lineString = getLineString(points);
    geomData.setGeometry(lineString);
    featureRow.setGeometry(geomData);
    return featureDao.insert(featureRow);
}