Java Code Examples for mil.nga.sf.Point#getX()

The following examples show how to use mil.nga.sf.Point#getX() . 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
/**
 * 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 2
Source Project: mage-android   File: LocationLoadTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
	CloseableIterator<Location> iterator = null;
	try {
		iterator = iterator();
		while (iterator.hasNext() && !isCancelled()) {
			Location location = iterator.current();
			User user = location.getUser();
			if (user == null) {
				continue;
			}

			Point point = GeometryUtils.getCentroid(location.getGeometry());
			LatLng latLng = new LatLng(point.getY(), point.getX());
			MarkerOptions options = new MarkerOptions().position(latLng).icon(LocationBitmapFactory.bitmapDescriptor(context, location, user));

			publishProgress(new Pair<>(options, new Pair<>(location, user)));
		}
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		if (iterator != null) {
			iterator.closeQuietly();
		}
	}

	return null;
}
 
Example 3
Source Project: mage-android   File: MapUtils.java    License: 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 4
Source Project: mage-android   File: MapUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean intersects(Point point1Start, Point point1End, Point point2Start, Point point2End) {
    double q =
            //Distance between the lines' starting rows times line2's horizontal length
            (point1Start.getY() - point2Start.getY()) * (point2End.getX() - point2Start.getX())
                    //Distance between the lines' starting columns times line2's vertical length
                    - (point1Start.getX() - point2Start.getX()) * (point2End.getY() - point2Start.getY());
    double d =
        //Line 1's horizontal length times line 2's vertical length
        (point1End.getX() - point1Start.getX()) * (point2End.getY() - point2Start.getY())
                //Line 1's vertical length times line 2's horizontal length
                - (point1End.getY() - point1Start.getY()) * (point2End.getX() - point2Start.getX());

    if (d == 0) {
        return false;
    }

    double r = q / d;

    q =
        //Distance between the lines' starting rows times line 1's horizontal length
        (point1Start.getY() - point2Start.getY()) * (point1End.getX() - point1Start.getX())
                //Distance between the lines' starting columns times line 1's vertical length
                - (point1Start.getX() - point2Start.getX()) * (point1End.getY() - point1Start.getY());

    double s = q / d;

    if( r < 0 || r > 1 || s < 0 || s > 1 ) {
        return false;
    }

    return true;
}
 
Example 5
@Override
public boolean onMarkerClick(Marker marker) {

    boolean handled = false;

    Observation observation = mapObservations.getMarkerObservation(marker.getId());
    if (observation != null) {
        final Geometry g = observation.getGeometry();
        if (g != null) {
            Point point = GeometryUtils.getCentroid(g);
            LatLng latLng = new LatLng(point.getY(), point.getX());
            Float accuracy = observation.getAccuracy();
            if (accuracy != null) {
                try {
                    if (observationAccuracyCircle != null) {
                        observationAccuracyCircle.second.remove();
                    }

                    Circle circle = map.addCircle(new CircleOptions()
                        .center(latLng)
                        .radius(accuracy)
                        .fillColor(context.getResources().getColor(R.color.accuracy_circle_fill))
                        .strokeColor(context.getResources().getColor(R.color.accuracy_circle_stroke))
                        .strokeWidth(2.0f));

                    observationAccuracyCircle = new Pair<>(observation.getRemoteId(), circle);
                } catch (NumberFormatException nfe) {
                    Log.e(LOG_NAME, "Problem adding accuracy circle to the map.", nfe);
                }
            }
        }

        map.setInfoWindowAdapter(infoWindowAdapter);
        marker.showInfoWindow();
        handled = true;
    }

    return handled;
}
 
Example 6
Source Project: mage-android   File: LocationTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Void doInBackground(Location... locations) {        
	for (Location location : locations) {
        User user = location.getUser();
        if (user == null) {
            continue;
        }

        boolean passesFilter = true;
        for (Filter filter : filters) {
            passesFilter = filter.passesFilter(location);
            if (!passesFilter) {
                break;
            }
        }

        if (passesFilter) {
            Point point = GeometryUtils.getCentroid(location.getGeometry());
            LatLng latLng = new LatLng(point.getY(), point.getX());
            MarkerOptions options = new MarkerOptions().position(latLng).icon(LocationBitmapFactory.bitmapDescriptor(context, location, user));

            publishProgress(new Pair<>(options, new Pair<>(location, user)));
        }
    }
    
    return null;
}
 
Example 7
@Override
public void onMapReady(final GoogleMap map) {
    ObservationLocation location = getIntent().getParcelableExtra(ObservationEditActivity.LOCATION);
    Point centroid = location.getCentroid();
    LatLng latLng = new LatLng(centroid.getY(), centroid.getX());

    float zoom = getIntent().getFloatExtra(ObservationEditActivity.INITIAL_ZOOM, 0);

    map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));

}
 
Example 8
@Override
public boolean onMarkerClick(Marker marker) {
	Pair<Location, User> pair = markerIdToPair.get(marker.getId());
	if (pair == null) {
		return false;
	}

	Location location = pair.first;
	User user = pair.second;

	final Geometry g = location.getGeometry();
	if (g != null) {
		Point point = GeometryUtils.getCentroid(g);
		LatLng latLng = new LatLng(point.getY(), point.getX());
		LocationProperty accuracyProperty = location.getPropertiesMap().get("accuracy");
		if (accuracyProperty != null && !accuracyProperty.getValue().toString().trim().isEmpty()) {
			try {
				float accuracy = Float.parseFloat(accuracyProperty.getValue().toString());
				if (clickedAccuracyCircle != null) {
					clickedAccuracyCircle.remove();
				}

				int color = LocationBitmapFactory.locationColor(context, location);
				clickedAccuracyCircle = map.addCircle(new CircleOptions()
						.center(latLng)
						.radius(accuracy)
						.fillColor(ColorUtils.setAlphaComponent(color, (int) (256 * .20)))
						.strokeColor(ColorUtils.setAlphaComponent(color, (int) (256 * .87)))
						.strokeWidth(2.0f));
				clickedAccuracyCircleUserId = user.getId();
			} catch (NumberFormatException nfe) {
				Log.e(LOG_NAME, "Problem adding accuracy circle to the map.", nfe);
			}
		}
	}

	map.setInfoWindowAdapter(infoWindowAdapter);
	// make sure to set the Anchor after this call as well, because the size of the icon might have changed
	marker.setIcon(LocationBitmapFactory.bitmapDescriptor(context, location, user));
	marker.setAnchor(0.5f, 1.0f);
	marker.showInfoWindow();
	return true;
}
 
Example 9
@Override
public LatLng getPosition() {
    Point point = GeometryUtils.getCentroid(observation.getGeometry());
    return new LatLng(point.getY(), point.getX());
}
 
Example 10
/**
 * Determine if the point is within the bounding box
 *
 * @param point
 *            bounding box
 * @param boundingBox
 *            bounding box
 *
 * @return true if within the bounding box
 * @since 2.0.0
 */
public static boolean isPointInBoundingBox(Point point,
		BoundingBox boundingBox) {
	BoundingBox pointBoundingbox = new BoundingBox(point.getX(),
			point.getY(), point.getX(), point.getY());
	return boundingBox.intersects(pointBoundingbox, true);
}
 
Example 11
/**
 * Determine if the point is within the bounding box
 *
 * @param point
 *            bounding box
 * @param boundingBox
 *            bounding box
 * @param maxLongitude
 *            max longitude of the world for the current bounding box units
 *
 * @return true if within the bounding box
 * @since 2.0.0
 */
public static boolean isPointInBoundingBox(Point point,
		BoundingBox boundingBox, double maxLongitude) {
	BoundingBox pointBoundingbox = new BoundingBox(point.getX(),
			point.getY(), point.getX(), point.getY());
	BoundingBox overlap = overlap(boundingBox, pointBoundingbox,
			maxLongitude, true);
	return overlap != null;
}
 
Example 12
/**
 * Get the tile grid for the location specified as the projection
 * 
 * @param point
 *            point
 * @param zoom
 *            zoom level
 * @param projection
 *            projection
 * @return tile grid
 * @since 1.1.0
 */
public static TileGrid getTileGrid(Point point, int zoom,
		Projection projection) {
	ProjectionTransform toWebMercator = projection
			.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
	Point webMercatorPoint = toWebMercator.transform(point);
	BoundingBox boundingBox = new BoundingBox(webMercatorPoint.getX(),
			webMercatorPoint.getY(), webMercatorPoint.getX(),
			webMercatorPoint.getY());
	return getTileGrid(boundingBox, zoom);
}
 
Example 13
/**
 * Convert a {@link Point} to a {@link LatLng}
 *
 * @param point point
 * @return lat lng
 */
public LatLng toLatLng(Point point) {
    point = toWgs84(point);
    LatLng latLng = new LatLng(point.getY(), point.getX());
    return latLng;
}
 
Example 14
/**
 * Get the first point from the geometry as a {@link LatLng}
 *
 * @return lat lng
 */
private LatLng getFirstLatLng() {
    Point point = getFirstPoint();
    return new LatLng(point.getY(), point.getX());
}
 
Example 15
/**
 * Get the geometry centroid as a LatLng
 *
 * @return centroid point lat lng
 */
public LatLng getCentroidLatLng() {
    Point point = GeometryUtils.getCentroid(geometry);
    return new LatLng(point.getY(), point.getX());
}