Java Code Examples for mil.nga.sf.LineString

The following examples show how to use mil.nga.sf.LineString. These examples are extracted from open source projects. 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 Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: 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 2
Source Project: geopackage-android-map   Source File: TestUtils.java    License: 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 3
/**
 * 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 4
/**
 * 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 5
/**
 * 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 6
Source Project: geopackage-android   Source File: DefaultFeatureTiles.java    License: 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 7
Source Project: geopackage-android   Source File: DefaultFeatureTiles.java    License: 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 8
Source Project: geopackage-android   Source File: GeoPackagePerformance.java    License: 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 9
Source Project: geopackage-android   Source File: TestUtils.java    License: 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 10
Source Project: geopackage-java   Source File: DefaultFeatureTiles.java    License: 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 11
Source Project: geopackage-java   Source File: GeoPackagePerformance.java    License: 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 Project: geopackage-java   Source File: TestUtils.java    License: 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 13
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: 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 14
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: 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 15
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: 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 16
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: MIT License 5 votes vote down vote up
/**
 * Convert a list of List<LatLng> to a {@link MultiLineString}
 *
 * @param polylineList polyline list
 * @param hasZ         has z flag
 * @param hasM         has m flag
 * @return multi line string
 */
public MultiLineString toMultiLineStringFromList(
        List<List<LatLng>> polylineList, boolean hasZ, boolean hasM) {

    MultiLineString multiLineString = new MultiLineString(hasZ, hasM);

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

    return multiLineString;
}
 
Example 17
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: 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 18
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: MIT License 5 votes vote down vote up
/**
 * Convert a {@link MultiPolylineOptions} to a {@link MultiLineString}
 *
 * @param multiPolylineOptions multi polyline options
 * @param hasZ                 has z flag
 * @param hasM                 has m flag
 * @return multi line string
 */
public MultiLineString toMultiLineStringFromOptions(
        MultiPolylineOptions multiPolylineOptions, boolean hasZ,
        boolean hasM) {

    MultiLineString multiLineString = new MultiLineString(hasZ, hasM);

    for (PolylineOptions polyline : multiPolylineOptions
            .getPolylineOptions()) {
        LineString lineString = toLineString(polyline);
        multiLineString.addLineString(lineString);
    }

    return multiLineString;
}
 
Example 19
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: MIT License 5 votes vote down vote up
/**
 * 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 toCompoundCurveFromOptions(
        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;
}
 
Example 20
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: MIT License 5 votes vote down vote up
/**
 * Convert a {@link CompoundCurve} to a {@link MultiPolylineOptions}
 *
 * @param compoundCurve compound curve
 * @return multi polyline options
 */
public MultiPolylineOptions toPolylines(CompoundCurve compoundCurve) {

    MultiPolylineOptions polylines = new MultiPolylineOptions();

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

    return polylines;
}
 
Example 21
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 22
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 23
/**
 * Test the LineString conversion
 * 
 * @param converter
 * @param lineString
 */
private static void convertLineString(GoogleMapShapeConverter converter,
		LineString lineString) {

	PolylineOptions polyline = converter.toPolyline(lineString);
	TestCase.assertNotNull(polyline);

	compareLineStringAndPolyline(converter, lineString, polyline);

	LineString lineString2 = converter.toLineString(polyline);
	compareLineStrings(lineString, lineString2);
}
 
Example 24
/**
 * 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 25
/**
 * 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 26
/**
 * 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 27
Source Project: geopackage-android   Source File: FeatureUtils.java    License: 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 28
Source Project: geopackage-android   Source File: FeatureUtils.java    License: 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 29
Source Project: geopackage-android   Source File: GeoPackageGeometryDataUtils.java    License: 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 Project: geopackage-android   Source File: FeatureTileUtils.java    License: 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);
}