Java Code Examples for mil.nga.sf.Point

The following examples show how to use mil.nga.sf.Point. 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: GoogleMapShapeConverter.java    License: MIT License 6 votes vote down vote up
/**
 * When the simplify tolerance is set, simplify the points to a similar
 * curve with fewer points.
 *
 * @param points ordered points
 * @return simplified points
 */
private List<Point> simplifyPoints(List<Point> points) {

    List<Point> simplifiedPoints = null;
    if (simplifyTolerance != null) {

        // Reproject to web mercator if not in meters
        if (projection != null && !projection.isUnit(Units.METRES)) {
            points = toWebMercator.transform(points);
        }

        // Simplify the points
        simplifiedPoints = GeometryUtils.simplifyPoints(points,
                simplifyTolerance);

        // Reproject back to the original projection
        if (projection != null && !projection.isUnit(Units.METRES)) {
            simplifiedPoints = fromWebMercator.transform(simplifiedPoints);
        }
    } else {
        simplifiedPoints = points;
    }

    return simplifiedPoints;
}
 
Example 3
Source Project: geopackage-android-map   Source File: TestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Create a random point
 *
 * @param hasZ
 * @param hasM
 * @return
 */
public static Point createPoint(boolean hasZ, boolean hasM) {

    double x = Math.random() * 180.0 * (Math.random() < .5 ? 1 : -1);
    double y = Math.random() * 90.0 * (Math.random() < .5 ? 1 : -1);

    Point point = new Point(hasZ, hasM, x, y);

    if (hasZ) {
        double z = Math.random() * 1000.0;
        point.setZ(z);
    }

    if (hasM) {
        double m = Math.random() * 1000.0;
        point.setM(m);
    }

    return point;
}
 
Example 4
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 5
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 6
Source Project: geopackage-android   Source File: DefaultFeatureTiles.java    License: MIT License 6 votes vote down vote up
/**
 * Add a ring
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param boundingBox       bounding box
 * @param transform         projection transform
 * @param path              path
 * @param points            points
 */
private void addRing(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Path path, List<Point> points) {

    // 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);
        }
    }
    path.close();
}
 
Example 7
Source Project: geopackage-android   Source File: FeatureUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Validate Point
 *
 * @param topGeometry
 * @param point
 */
private static void validatePoint(Geometry topGeometry, Point point) {

    TestCase.assertEquals(GeometryType.POINT, point.getGeometryType());

    validateZAndM(topGeometry, point);

    if (topGeometry.hasZ()) {
        TestCase.assertNotNull(point.getZ());
    } else {
        TestCase.assertNull(point.getZ());
    }

    if (topGeometry.hasM()) {
        TestCase.assertNotNull(point.getM());
    } else {
        TestCase.assertNull(point.getM());
    }
}
 
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 point
 *
 * @param hasZ
 * @param hasM
 * @return
 */
public static Point createPoint(boolean hasZ, boolean hasM) {

    double x = Math.random() * 180.0 * (Math.random() < .5 ? 1 : -1);
    double y = Math.random() * ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE * (Math.random() < .5 ? 1 : -1);

    Point point = new Point(hasZ, hasM, x, y);

    if (hasZ) {
        double z = Math.random() * 1000.0;
        point.setZ(z);
    }

    if (hasM) {
        double m = Math.random() * 1000.0;
        point.setM(m);
    }

    return point;
}
 
Example 10
Source Project: geopackage-android   Source File: GeoPackageGeometryDataUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Compare the two points for equality
 *
 * @param expected
 * @param actual
 */
private static void comparePoint(Point expected, Point actual, double delta) {

    compareBaseGeometryAttributes(expected, actual);
    TestCase.assertEquals(expected.getX(), actual.getX(), delta);
    TestCase.assertEquals(expected.getY(), actual.getY(), delta);
    if (expected.getZ() == null) {
        TestCase.assertEquals(expected.getZ(), actual.getZ());
    } else {
        TestCase.assertEquals(expected.getZ(), actual.getZ(), delta);
    }
    if (expected.getM() == null) {
        TestCase.assertEquals(expected.getM(), actual.getM());
    } else {
        TestCase.assertEquals(expected.getM(), actual.getM(), delta);
    }
}
 
Example 11
Source Project: mage-android   Source File: ObservationTask.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Void doInBackground(Observation... observations) {
    for (Observation o : observations) {
        boolean passesFilter = true;
        for (Filter filter : filters) {
            passesFilter = filter.passesFilter(o);
            if (!passesFilter) {
                break;
            }
        }

        if (passesFilter) {
            Geometry geometry = o.getGeometry();
            Point centroid = GeometryUtils.getCentroid(geometry);
            MarkerOptions options = new MarkerOptions().position(new LatLng(centroid.getY(), centroid.getX())).icon(ObservationBitmapFactory.bitmapDescriptor(context, o));
            publishProgress(new Pair<>(options, o));
        }
    }

    return null;
}
 
Example 12
Source Project: mage-android   Source File: ObservationLoadTask.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Void doInBackground(Void... params ) {
    CloseableIterator<Observation> iterator = null;
    try {
        iterator = iterator();
        while (iterator.hasNext() && !isCancelled()) {
            Observation o = iterator.current();
            Geometry geometry = o.getGeometry();
            Point centroid = GeometryUtils.getCentroid(geometry);
            MarkerOptions options = new MarkerOptions().position(new LatLng(centroid.getY(), centroid.getX())).icon(ObservationBitmapFactory.bitmapDescriptor(context, o));

            publishProgress(new Pair<>(options, o));
        }

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        if (iterator != null) {
            iterator.closeQuietly();
        }
    }

    return null;
}
 
Example 13
Source Project: mage-android   Source File: ObservationLocation.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check if the points form a rectangle and return if the side one has the same x
 *
 * @param points points
 * @return null if not a rectangle, true if same x side 1, false if same y side 1
 */
public static Boolean checkIfRectangleAndFindSide(List<Point> points) {
    Boolean sameXSide1 = null;
    int size = points.size();
    if (size == 4 || size == 5) {
        Point point1 = points.get(0);
        Point lastPoint = points.get(points.size() - 1);
        boolean closed = point1.getX() == lastPoint.getX() && point1.getY() == lastPoint.getY();
        if ((closed && size == 5) || (!closed && size == 4)) {
            Point point2 = points.get(1);
            Point point3 = points.get(2);
            Point point4 = points.get(3);
            if (point1.getX() == point2.getX() && point2.getY() == point3.getY()) {
                if (point1.getY() == point4.getY() && point3.getX() == point4.getX()) {
                    sameXSide1 = true;
                }
            } else if (point1.getY() == point2.getY() && point2.getX() == point3.getX()) {
                if (point1.getX() == point4.getX() && point3.getY() == point4.getY()) {
                    sameXSide1 = false;
                }
            }
        }
    }
    return sameXSide1;
}
 
Example 14
Source Project: geopackage-java   Source File: FeatureUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Validate Point
 * 
 * @param topGeometry
 * @param point
 */
private static void validatePoint(Geometry topGeometry, Point point) {

	TestCase.assertEquals(GeometryType.POINT, point.getGeometryType());

	validateZAndM(topGeometry, point);

	if (topGeometry.hasZ()) {
		TestCase.assertNotNull(point.getZ());
	} else {
		TestCase.assertNull(point.getZ());
	}

	if (topGeometry.hasM()) {
		TestCase.assertNotNull(point.getM());
	} else {
		TestCase.assertNull(point.getM());
	}
}
 
Example 15
Source Project: geopackage-java   Source File: GeoPackageGeometryDataUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Compare the two points for equality
 * 
 * @param expected
 * @param actual
 */
private static void comparePoint(Point expected, Point actual, double delta) {

	compareBaseGeometryAttributes(expected, actual);
	TestCase.assertEquals(expected.getX(), actual.getX(), delta);
	TestCase.assertEquals(expected.getY(), actual.getY(), delta);
	if (expected.getZ() == null) {
		TestCase.assertEquals(expected.getZ(), actual.getZ());
	} else {
		TestCase.assertEquals(expected.getZ(), actual.getZ(), delta);
	}
	if (expected.getM() == null) {
		TestCase.assertEquals(expected.getM(), actual.getM());
	} else {
		TestCase.assertEquals(expected.getM(), actual.getM(), delta);
	}
}
 
Example 16
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 17
Source Project: geopackage-java   Source File: TestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Create a random point
 * 
 * @param hasZ
 * @param hasM
 * @return point
 */
public static Point createPoint(boolean hasZ, boolean hasM) {

	double x = Math.random() * 180.0 * (Math.random() < .5 ? 1 : -1);
	double y = Math.random()
			* ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE
			* (Math.random() < .5 ? 1 : -1);

	Point point = new Point(hasZ, hasM, x, y);

	if (hasZ) {
		double z = Math.random() * 1000.0;
		point.setZ(z);
	}

	if (hasM) {
		double m = Math.random() * 1000.0;
		point.setM(m);
	}

	return point;
}
 
Example 18
Source Project: geopackage-java   Source File: UrlTileGeneratorUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test generating tiles with random bounds and zoomss
 * 
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
public static void testGenerateTilesRandom(GeoPackage geoPackage)
		throws SQLException, IOException {

	for (int i = 0; i < 10; i++) {

		int minZoom = (int) (Math.random() * 3.0);
		int maxZoom = minZoom + ((int) (Math.random() * 3.0));
		Point point1 = TestUtils.createPoint(false, false);
		Point point2 = TestUtils.createPoint(false, false);
		BoundingBox boundingBox = new BoundingBox(Math.min(point1.getX(),
				point2.getX()), Math.min(point1.getY(), point2.getY()),
				Math.max(point1.getX(), point2.getX()), Math.max(
						point1.getY(), point2.getY()));
		UrlTileGenerator tileGenerator = new UrlTileGenerator(geoPackage,
				TABLE_NAME + i, URL, minZoom, maxZoom, boundingBox,
				getProjection());

		testGenerateTiles(tileGenerator);
	}
}
 
Example 19
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: MIT License 5 votes vote down vote up
/**
 * Transform a projection point to WGS84
 *
 * @param point projection point
 * @return WGS84 point
 */
public Point toWgs84(Point point) {
    if (projection != null) {
        point = toWgs84.transform(point);
    }
    return point;
}
 
Example 20
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: MIT License 5 votes vote down vote up
/**
 * Transform a WGS84 point to the projection
 *
 * @param point WGS84 point
 * @return projection point
 */
public Point toProjection(Point point) {
    if (projection != null) {
        point = fromWgs84.transform(point);
    }
    return point;
}
 
Example 21
Source Project: geopackage-java   Source File: FeatureTileUtils.java    License: MIT License 5 votes vote down vote up
public static void setPoint(FeatureRow featureRow, double x, double y) {
	GeoPackageGeometryData geomData = new GeoPackageGeometryData(
			ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
	Point point = new Point(false, false, x, y);
	geomData.setGeometry(point);
	featureRow.setGeometry(geomData);
}
 
Example 22
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 23
Source Project: geopackage-java   Source File: FeatureTileUtils.java    License: 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 24
Source Project: geopackage-android-map   Source File: GoogleMapShapeConverter.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 25
Source Project: geopackage-android-map   Source File: FeatureOverlayQuery.java    License: MIT License 5 votes vote down vote up
/**
 * Determine if the feature overlay is on for the provided zoom level at the location
 *
 * @param zoom   zoom level
 * @param latLng lat lon location
 * @return true if on
 * @since 1.2.6
 */
public boolean isOnAtCurrentZoom(double zoom, LatLng latLng) {

    Point point = new Point(latLng.longitude, latLng.latitude);
    TileGrid tileGrid = TileBoundingBoxUtils.getTileGridFromWGS84(point, (int) zoom);

    boolean on = boundedOverlay.hasTile((int) tileGrid.getMinX(), (int) tileGrid.getMinY(), (int) zoom);
    return on;
}
 
Example 26
/**
 * Compare Point with LatLng
 *
    * @param converter
 * @param point
 * @param latLng
 */
private static void comparePointAndLatLng(GoogleMapShapeConverter converter, Point point, LatLng latLng) {
       if(converter != null){
           point = converter.toWgs84(point);
       }
	TestCase.assertEquals(point.getX(), latLng.longitude, 0.001);
	TestCase.assertEquals(point.getY(), latLng.latitude, 0.001);
}
 
Example 27
/**
 * Compare list of points and lat longs
 *
    * @param converter
 * @param points
 * @param points2
 */
private static void comparePointsAndLatLngs(GoogleMapShapeConverter converter, List<Point> points,
		List<LatLng> points2) {
	TestCase.assertEquals(points.size(), points2.size());

	for (int i = 0; i < points.size(); i++) {
		comparePointAndLatLng(converter, points.get(i), points2.get(i));
	}
}
 
Example 28
/**
 * Compare two lists of points
 * 
 * @param points
 * @param points2
 */
private static void comparePoints(List<Point> points, List<Point> points2) {
	TestCase.assertEquals(points.size(), points2.size());

	for (int i = 0; i < points.size(); i++) {
		comparePoints(points.get(i), points2.get(i));
	}
}
 
Example 29
/**
 * Test the MultiPoint conversion
 * 
 * @param converter
 * @param multiPoint
 */
private static void convertMultiPoint(GoogleMapShapeConverter converter,
		MultiPoint multiPoint) {

	MultiLatLng latLngs = converter.toLatLngs(multiPoint);
	TestCase.assertNotNull(latLngs);
	TestCase.assertFalse(latLngs.getLatLngs().isEmpty());

	List<Point> points = multiPoint.getPoints();
	comparePointsAndLatLngs(converter, points, latLngs.getLatLngs());

	MultiPoint multiPoint2 = converter.toMultiPoint(latLngs);
	comparePoints(multiPoint.getPoints(), multiPoint2.getPoints());
}
 
Example 30
Source Project: geopackage-android   Source File: FeatureTiles.java    License: MIT License 5 votes vote down vote up
/**
 * When the simplify tolerance is set, simplify the points to a similar
 * curve with fewer points.
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param points            ordered points
 * @return simplified points
 * @since 2.0.0
 */
protected List<Point> simplifyPoints(double simplifyTolerance,
                                     List<Point> points) {

    List<Point> simplifiedPoints = null;
    if (simplifyGeometries) {

        // Reproject to web mercator if not in meters
        if (projection != null && !projection.isUnit(Units.METRES)) {
            ProjectionTransform toWebMercator = projection
                    .getTransformation(WEB_MERCATOR_PROJECTION);
            points = toWebMercator.transform(points);
        }

        // Simplify the points
        simplifiedPoints = GeometryUtils.simplifyPoints(points,
                simplifyTolerance);

        // Reproject back to the original projection
        if (projection != null && !projection.isUnit(Units.METRES)) {
            ProjectionTransform fromWebMercator = WEB_MERCATOR_PROJECTION
                    .getTransformation(projection);
            simplifiedPoints = fromWebMercator.transform(simplifiedPoints);
        }
    } else {
        simplifiedPoints = points;
    }

    return simplifiedPoints;
}