use of com.esri.core.geometry.Point in project android-gps-test-tool by Esri.
the class GPSTesterActivityController method addGraphicLatLon.
/**
* Helper method that uses latitude/longitude points to programmatically
* draw a <code>SimpleMarkerSymbol</code> and adds the <code>Graphic</code> to map.
* @param latitude
* @param longitude
* @param attributes
* @param style You defined the style via the Enum <code>SimpleMarkerSymbol.STYLE</code>
*/
public static void addGraphicLatLon(double latitude, double longitude, Map<String, Object> attributes, SimpleMarkerSymbol.STYLE style, int color, int size, GraphicsLayer graphicsLayer, MapView map) {
Point latlon = new Point(longitude, latitude);
//Convert latlon Point to mercator map point.
Point point = (Point) GeometryEngine.project(latlon, SpatialReference.create(4326), map.getSpatialReference());
//Set market's color, size and style. You can customize these as you see fit
SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(color, size, style);
Graphic graphic = new Graphic(point, symbol, attributes);
graphicsLayer.addGraphic(graphic);
}
use of com.esri.core.geometry.Point in project sis by apache.
the class ESRI method tryGetCoordinate.
/**
* If the given point is an implementation of this library, returns its coordinate.
* Otherwise returns {@code null}. If non-null, the returned array may have a length of 2 or 3.
*/
@Override
final double[] tryGetCoordinate(final Object point) {
if (point instanceof Point) {
final Point pt = (Point) point;
final double z = pt.getZ();
final double[] coord;
if (Double.isNaN(z)) {
coord = new double[2];
} else {
coord = new double[3];
coord[2] = z;
}
coord[1] = pt.getY();
coord[0] = pt.getX();
return coord;
}
return null;
}
use of com.esri.core.geometry.Point in project sis by apache.
the class EnvelopeOperationTest method run.
/**
* Implementation of the test methods.
*/
private static void run(final AbstractFeature feature) {
assertNull("Before a geometry is set", feature.getPropertyValue("bounds"));
GeneralEnvelope expected;
// Set one geometry
Polygon classes = new Polygon();
classes.startPath(10, 20);
classes.lineTo(10, 30);
classes.lineTo(15, 30);
classes.lineTo(15, 20);
feature.setPropertyValue("classes", classes);
expected = new GeneralEnvelope(HardCodedCRS.WGS84_φλ);
expected.setRange(0, 10, 15);
expected.setRange(1, 20, 30);
assertEnvelopeEquals(expected, (Envelope) feature.getPropertyValue("bounds"));
// Set second geometry
Point wall = new Point(18, 40);
feature.setPropertyValue("climbing wall", wall);
expected = new GeneralEnvelope(HardCodedCRS.WGS84_φλ);
expected.setRange(0, 10, 18);
expected.setRange(1, 20, 40);
assertEnvelopeEquals(expected, (Envelope) feature.getPropertyValue("bounds"));
// Set third geometry. This geometry has CRS axis order reversed.
Polygon gymnasium = new Polygon();
gymnasium.startPath(-5, -30);
gymnasium.lineTo(-6, -30);
gymnasium.lineTo(-6, -31);
gymnasium.lineTo(-5, -31);
feature.setPropertyValue("gymnasium", gymnasium);
expected = new GeneralEnvelope(HardCodedCRS.WGS84_φλ);
expected.setRange(0, -31, 18);
expected.setRange(1, -6, 40);
assertEnvelopeEquals(expected, (Envelope) feature.getPropertyValue("bounds"));
}
use of com.esri.core.geometry.Point in project sis by apache.
the class WriterTest method testFeatures.
/**
* Writes way points, routes or tracks in the given store.
*
* @param store the store where to write.
* @param type the kind of feature to write: way point, route or track.
*/
private void testFeatures(final Store store, final Type type) throws Exception {
final Types types = Types.DEFAULT;
/*
* Way Points as defined in "waypoint.xml" test file.
* Appear also in "route.xml" and "track.xml" files.
*/
final AbstractFeature point1 = types.wayPoint.newInstance();
point1.setPropertyValue("sis:geometry", new Point(15, 10));
point1.setPropertyValue("time", Instant.parse("2010-01-10T00:00:00Z"));
point1.setPropertyValue("name", "first point");
point1.setPropertyValue("cmt", "first comment");
point1.setPropertyValue("desc", "first description");
point1.setPropertyValue("src", "first source");
point1.setPropertyValue("sym", "first symbol");
point1.setPropertyValue("type", "first type");
point1.setPropertyValue("ele", 140.0);
point1.setPropertyValue("magvar", 35.0);
point1.setPropertyValue("geoidheight", 112.32);
point1.setPropertyValue("sat", 11);
point1.setPropertyValue("hdop", 15.15);
point1.setPropertyValue("vdop", 14.14);
point1.setPropertyValue("pdop", 13.13);
point1.setPropertyValue("ageofdgpsdata", 55.55);
point1.setPropertyValue("dgpsid", 256);
point1.setPropertyValue("fix", Fix.NONE);
point1.setPropertyValue("link", Arrays.asList(new Link(new URI("http://first-address1.org")), new Link(new URI("http://first-address2.org")), new Link(new URI("http://first-address3.org"))));
final AbstractFeature point3 = types.wayPoint.newInstance();
point3.setPropertyValue("sis:geometry", new Point(35, 30));
point3.setPropertyValue("time", Instant.parse("2010-01-30T00:00:00Z"));
point3.setPropertyValue("name", "third point");
point3.setPropertyValue("cmt", "third comment");
point3.setPropertyValue("desc", "third description");
point3.setPropertyValue("src", "third source");
point3.setPropertyValue("sym", "third symbol");
point3.setPropertyValue("type", "third type");
point3.setPropertyValue("ele", 150.0);
point3.setPropertyValue("magvar", 25.0);
point3.setPropertyValue("geoidheight", 142.32);
point3.setPropertyValue("sat", 35);
point3.setPropertyValue("hdop", 35.15);
point3.setPropertyValue("vdop", 34.14);
point3.setPropertyValue("pdop", 33.13);
point3.setPropertyValue("ageofdgpsdata", 85.55);
point3.setPropertyValue("dgpsid", 456);
point3.setPropertyValue("fix", Fix.THREE_DIMENSIONAL);
point3.setPropertyValue("link", Arrays.asList(new Link(new URI("http://third-address1.org")), new Link(new URI("http://third-address2.org"))));
final AbstractFeature point2 = types.wayPoint.newInstance();
point2.setPropertyValue("sis:geometry", new Point(25, 20));
final List<AbstractFeature> wayPoints = Arrays.asList(point1, point2, point3);
final List<AbstractFeature> features;
switch(type) {
case WAY_POINT:
{
features = wayPoints;
break;
}
case ROUTE:
{
final AbstractFeature route1 = types.route.newInstance();
route1.setPropertyValue("name", "Route name");
route1.setPropertyValue("cmt", "Route comment");
route1.setPropertyValue("desc", "Route description");
route1.setPropertyValue("src", "Route source");
route1.setPropertyValue("type", "Route type");
route1.setPropertyValue("number", 7);
route1.setPropertyValue("rtept", wayPoints);
route1.setPropertyValue("link", Arrays.asList(new Link(new URI("http://route-address1.org")), new Link(new URI("http://route-address2.org")), new Link(new URI("http://route-address3.org"))));
final AbstractFeature route2 = types.route.newInstance();
features = Arrays.asList(route1, route2);
break;
}
case TRACK:
{
final AbstractFeature seg1 = types.trackSegment.newInstance();
final AbstractFeature seg2 = types.trackSegment.newInstance();
seg1.setPropertyValue("trkpt", wayPoints);
final AbstractFeature track1 = types.track.newInstance();
track1.setPropertyValue("name", "Track name");
track1.setPropertyValue("cmt", "Track comment");
track1.setPropertyValue("desc", "Track description");
track1.setPropertyValue("src", "Track source");
track1.setPropertyValue("type", "Track type");
track1.setPropertyValue("number", 7);
track1.setPropertyValue("trkseg", Arrays.asList(seg1, seg2));
track1.setPropertyValue("link", Arrays.asList(new Link(new URI("http://track-address1.org")), new Link(new URI("http://track-address2.org")), new Link(new URI("http://track-address3.org"))));
final AbstractFeature track2 = types.track.newInstance();
features = Arrays.asList(track1, track2);
break;
}
default:
throw new AssertionError(type);
}
/*
* Add minimalist metadata and marshal.
*/
final Bounds bounds = new Bounds();
bounds.westBoundLongitude = -20;
bounds.eastBoundLongitude = 30;
bounds.southBoundLatitude = 10;
bounds.northBoundLatitude = 40;
final Metadata metadata = new Metadata();
metadata.bounds = bounds;
metadata.creator = "DataProducer";
store.write(metadata, features.stream());
}
use of com.esri.core.geometry.Point in project pigeon by aseldawy.
the class Connect method exec.
@Override
public DataByteArray exec(Tuple b) throws IOException {
try {
// Read information from input
Iterator<Tuple> firstPointIdIter = ((DataBag) b.get(0)).iterator();
Iterator<Tuple> lastPointIdIter = ((DataBag) b.get(1)).iterator();
Iterator<Tuple> shapesIter = ((DataBag) b.get(2)).iterator();
// Shapes that are created after connected line segments
Vector<OGCGeometry> createdShapes = new Vector<OGCGeometry>();
Vector<OGCLineString> linestrings = new Vector<OGCLineString>();
Vector<Long> firstPointId = new Vector<Long>();
Vector<Long> lastPointId = new Vector<Long>();
while (firstPointIdIter.hasNext() && lastPointIdIter.hasNext() && shapesIter.hasNext()) {
OGCGeometry geom = geometryParser.parseGeom(shapesIter.next().get(0));
long first_point_id = (Long) firstPointIdIter.next().get(0);
long last_point_id = (Long) lastPointIdIter.next().get(0);
if (geom.isEmpty()) {
// Skip empty geometries
} else if (geom instanceof OGCPolygon) {
// Copy to output directly. Polygons cannot be connected to other shapes.
createdShapes.add(geom);
} else if (geom instanceof OGCLineString) {
linestrings.add((OGCLineString) geom);
firstPointId.add(first_point_id);
lastPointId.add(last_point_id);
} else {
throw new GeoException("Cannot connect shapes of type " + geom.getClass());
}
}
if (firstPointIdIter.hasNext() || lastPointIdIter.hasNext() || shapesIter.hasNext()) {
throw new ExecException("All parameters should be of the same size (" + firstPointId.size() + "," + lastPointId.size() + "," + linestrings.size() + ")");
}
// Stores an ordered list of line segments in current connected block
Vector<OGCLineString> connected_lines = new Vector<OGCLineString>();
// Total number of points in all visited linestrings
int sumPoints = 0;
// Which linestrings to reverse upon connection
Vector<Boolean> reverse = new Vector<Boolean>();
long first_point_id = -1;
long last_point_id = -1;
// Reorder linestrings to form a contiguous list of connected linestrings
while (!linestrings.isEmpty()) {
// Loop invariant:
// At the beginning of each iteration, the lines in connected_lines are connected.
// In each iteration, we move one linestring from linestrings to connected_lines
// while keeping them connected
int size_before = connected_lines.size();
for (int i = 0; i < linestrings.size(); ) {
if (connected_lines.isEmpty()) {
// First linestring
first_point_id = firstPointId.remove(i);
last_point_id = lastPointId.remove(i);
reverse.add(false);
sumPoints += linestrings.get(i).numPoints();
connected_lines.add(linestrings.remove(i));
} else if (lastPointId.get(i) == first_point_id) {
// This linestring goes to the beginning of the list as-is
lastPointId.remove(i);
first_point_id = firstPointId.remove(i);
sumPoints += linestrings.get(i).numPoints();
connected_lines.add(0, linestrings.remove(i));
reverse.add(0, false);
} else if (firstPointId.get(i) == first_point_id) {
// Should go to the beginning after being reversed
firstPointId.remove(i);
first_point_id = lastPointId.remove(i);
sumPoints += linestrings.get(i).numPoints();
connected_lines.add(0, linestrings.remove(i));
reverse.add(0, true);
} else if (firstPointId.get(i) == last_point_id) {
// This linestring goes to the end of the list as-is
firstPointId.remove(i);
last_point_id = lastPointId.remove(i);
sumPoints += linestrings.get(i).numPoints();
connected_lines.add(linestrings.remove(i));
reverse.add(false);
} else if (lastPointId.get(i) == last_point_id) {
// Should go to the end after being reversed
lastPointId.remove(i);
last_point_id = firstPointId.remove(i);
sumPoints += linestrings.get(i).numPoints();
connected_lines.add(linestrings.remove(i));
reverse.add(true);
} else {
i++;
}
}
if (connected_lines.size() == size_before || linestrings.isEmpty()) {
// Cannot connect any more lines to the current block. Emit as a shape
boolean isPolygon = first_point_id == last_point_id;
Point[] points = new Point[sumPoints - connected_lines.size() + (isPolygon ? 0 : 1)];
int n = 0;
for (int i = 0; i < connected_lines.size(); i++) {
OGCLineString linestring = connected_lines.get(i);
boolean isReverse = reverse.get(i);
int last_i = (isPolygon || i < connected_lines.size() - 1) ? linestring.numPoints() - 1 : linestring.numPoints();
for (int i_point = 0; i_point < last_i; i_point++) {
points[n++] = (Point) linestring.pointN(isReverse ? linestring.numPoints() - 1 - i_point : i_point).getEsriGeometry();
}
}
MultiPath multi_path = isPolygon ? new Polygon() : new Polyline();
for (int i = 1; i < points.length; i++) {
Segment segment = new Line();
segment.setStart(points[i - 1]);
segment.setEnd(points[i]);
multi_path.addSegment(segment, false);
}
createdShapes.add(isPolygon ? new OGCPolygon((Polygon) multi_path, 0, SpatialReference.create(4326)) : new OGCLineString((Polyline) multi_path, 0, SpatialReference.create(4326)));
// Re-initialize all data structures to connect remaining lines
if (!linestrings.isEmpty()) {
connected_lines.clear();
reverse.clear();
sumPoints = 0;
}
}
}
if (createdShapes.size() == 1) {
return new DataByteArray(createdShapes.get(0).asBinary().array());
} else if (createdShapes.size() > 1) {
OGCGeometryCollection collection = new OGCConcreteGeometryCollection(createdShapes, createdShapes.get(0).getEsriSpatialReference());
return new DataByteArray(collection.asBinary().array());
} else {
throw new GeoException("No shapes to connect");
}
} catch (Exception e) {
throw new GeoException(e);
}
}
Aggregations