Java Code Examples for com.esri.core.geometry.Polygon#lineTo()

The following examples show how to use com.esri.core.geometry.Polygon#lineTo() . 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: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Example:
 * [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
 * @param parser
 * @return a polygon
 * @throws JsonParseException
 * @throws IOException
 */
private Polygon parseSimplePolygonCoordinates(JsonNode node) {
  Polygon g = new Polygon();
  boolean first = true;
  ArrayNode points = (ArrayNode) node;
  for (JsonNode point : points) {
    Point p = parsePointCoordinates(point);
    if (first) {
      g.startPath(p);
      first = false;
    } else {
      g.lineTo(p);
    }  
  }
  g.closeAllPaths();
  return g;
}
 
Example 2
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example 3
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example 4
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example 5
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example 6
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example 7
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example 8
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example 9
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example 10
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
public Polygon GenerateEllipse(Point center, double majorAxis, double minorAxis, double ra)
{
	Polygon ellipse = new Polygon();
	for (int i = 0; i < 360; ++i)
	{
		double theta = Math.toRadians(i);
		Point p = ellipsePtFromAngle(center, majorAxis, minorAxis, theta);
		p = GeometryUtility.Rotate(center, p, ra);
		if (i == 0) {
			ellipse.startPath(p);
		}
		else{
			ellipse.lineTo(p);
		}
	}
	ellipse.closeAllPaths();
	return ellipse;
}
 
Example 11
Source File: PolygonProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private com.esri.ges.spatial.Geometry constructCAPGeometry(String geoString)
		throws GeometryException {
	try {
		String[] pairs = geoString.split(" ");

		Polygon polygon = new Polygon();
		Boolean firstit = true;
		for (String coords : pairs) {

			String[] tuple = coords.split(",");
			Double x = Double.parseDouble(tuple[0]);
			Double y = Double.parseDouble(tuple[1]);
			Point p = new Point(x, y);
			Double z = Double.NaN;
			if (tuple.length > 2) {
				z = Double.parseDouble(tuple[2]);
				p.setZ(z);
			}
			if (firstit) {
				polygon.startPath(p);
				firstit = false;
			} else {
				polygon.lineTo(p);
			}
		}
		polygon.closeAllPaths();
		String json = GeometryEngine.geometryToJson(srIn, polygon);
		return spatial.fromJson(json);
	} catch (GeometryException ex) {
		LOG.error(ex.getMessage());
		LOG.error(ex.getStackTrace());
		return null;
	}
}
 
Example 12
Source File: ClusterLayer.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private Polygon getConvexHull(Cluster<ClusterableLocation> cluster) {
  List<ClusterableLocation> pointsList = cluster.getPoints();
  ClusterableLocation[] pointsArray = pointsList.toArray(new ClusterableLocation[pointsList.size()]);
  ClusterableLocation[] pointsConvexHull = ConvexHullGenerator.generateHull(pointsArray);
  Polygon convexHull = new Polygon();
  convexHull.startPath(pointsConvexHull[0].getPoint()[0], pointsConvexHull[0].getPoint()[1]);
  for (int i = 1; i < pointsConvexHull.length; i++) {
    ClusterableLocation p = pointsConvexHull[i];
    convexHull.lineTo(p.getPoint()[0], p.getPoint()[1]);
  }
  convexHull.closePathWithLine();
  return convexHull;
}
 
Example 13
Source File: TestStGeomFromShape.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
private static Polygon createPolygon() {
	Polygon polygon = new Polygon();
	polygon.startPath(createFirstLocation());
	polygon.lineTo(createSecondLocation());
	polygon.lineTo(createThirdLocation());
	polygon.lineTo(createFourthLocation());
	polygon.closeAllPaths();
	return polygon;
}
 
Example 14
Source File: SpatialQProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private MapGeometry constructGeometryFromString(String geoString) {
	String[] pairs = geoString.split(" ");

	Polygon polygon = new Polygon();
	Boolean firstit = true;
	for (String coords : pairs) {

		String[] tuple = coords.split(",");
		Double x = Double.parseDouble(tuple[0]);
		Double y = Double.parseDouble(tuple[1]);
		Point p = new Point(x, y);
		Double z = Double.NaN;
		if (tuple.length > 2) {
			z = Double.parseDouble(tuple[2]);
			p.setZ(z);
		}
		if (firstit) {
			polygon.startPath(p);
			firstit = false;
		} else {
			polygon.lineTo(p);
		}
	}
	polygon.closeAllPaths();
	MapGeometry mapgeo = new MapGeometry(polygon, srOut);
	return mapgeo;
}
 
Example 15
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private MapGeometry constructGeometryFromString(String geoString)
{
	String[] pairs = geoString.split(" ");
	
	Polygon polygon = new Polygon();
	Boolean firstit = true;
	for(String coords: pairs)
	{
		
		String[] tuple = coords.split(",");
		Double x = Double.parseDouble(tuple[0]);
		Double y = Double.parseDouble(tuple[1]);
		Point p = new Point(x,y);
		Double z = Double.NaN;
		if (tuple.length>2)
		{
			z = Double.parseDouble(tuple[2]);
			p.setZ(z);
		}
		if(firstit)
		{
			polygon.startPath(p);
			firstit=false;
		}
		else
		{
			polygon.lineTo(p);
		}
	}
	polygon.closeAllPaths();
	MapGeometry mapgeo = new MapGeometry(polygon, srOut);
	return mapgeo;
}
 
Example 16
Source File: RangeFanProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private Geometry constructRangeFan(double x, double y, double range,
		String unit, double bearing, double traversal) throws Exception {
	try {
		Polygon fan = new Polygon();
		Point center = new Point();
		center.setX(x);
		center.setY(y);

		Point centerProj = (Point) GeometryEngine.project(center, srIn,
				srBuffer);

		double centerX = centerProj.getX();
		double centerY = centerProj.getY();
		bearing = GeometryUtility.Geo2Arithmetic(bearing);
		double leftAngle = bearing - (traversal / 2);
		double rightAngle = bearing + (traversal / 2);
		int count = (int) Math.round(Math.abs(leftAngle - rightAngle));
		fan.startPath(centerProj);
		UnitConverter uc = new UnitConverter();
		range = uc.Convert(range, unit, srBuffer);
		for (int i = 0; i < count; ++i) {
			double d = Math.toRadians(leftAngle + i);
			double arcX = centerX + (range * Math.cos(d));
			double arcY = centerY + (range * Math.sin(d));
			Point arcPt = new Point(arcX, arcY);
			fan.lineTo(arcPt);
		}
		fan.closeAllPaths();
		return fan;
	} catch (Exception e) {
		LOG.error(e.getMessage());
		throw e;
	}
}
 
Example 17
Source File: EnvelopeOperationTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * 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"));
}
 
Example 18
Source File: RangeFanProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private Geometry constructRangeFan(double x, double y, double range,
		String unit, double bearing, double traversal)
		throws GeometryException {
	Polygon fan = new Polygon();
	Point center = new Point();
	center.setX(x);
	center.setY(y);
	// SpatialReference srIn = SpatialReference.create(wkidin);
	// SpatialReference srBuffer = SpatialReference.create(wkidbuffer);
	// SpatialReference srOut = SpatialReference.create(wkidout);
	Point centerProj = (Point) GeometryEngine.project(center, srIn,
			srBuffer);

	double centerX = centerProj.getX();
	double centerY = centerProj.getY();
	bearing = GeometryUtility.Geo2Arithmetic(bearing);
	double leftAngle = bearing - (traversal / 2);
	double rightAngle = bearing + (traversal / 2);
	int count = (int) Math.round(Math.abs(leftAngle - rightAngle));
	fan.startPath(centerProj);
	UnitConverter uc = new UnitConverter();
	range = uc.Convert(range, unit, srBuffer);
	for (int i = 0; i < count; ++i) {
		double d = Math.toRadians(leftAngle + i);
		double arcX = centerX + (range * Math.cos(d));
		double arcY = centerY + (range * Math.sin(d));
		Point arcPt = new Point(arcX, arcY);
		// arcPt = (Point) GeometryEngine.project(arcPt, srBuffer, srOut);
		fan.lineTo(arcPt);
	}
	fan.closeAllPaths();
	return fan;
}
 
Example 19
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private com.esri.ges.spatial.Geometry constructGeometryFromString(String geoString) throws GeometryException
{
	String[] pairs = geoString.split(" ");
	
	Polygon polygon = new Polygon();
	Boolean firstit = true;
	for(String coords: pairs)
	{
		
		String[] tuple = coords.split(",");
		Double x = Double.parseDouble(tuple[0]);
		Double y = Double.parseDouble(tuple[1]);
		Point p = new Point(x,y);
		Double z = Double.NaN;
		if (tuple.length>2)
		{
			z = Double.parseDouble(tuple[2]);
			p.setZ(z);
		}
		if(firstit)
		{
			polygon.startPath(p);
			firstit=false;
		}
		else
		{
			polygon.lineTo(p);
		}
	}
	polygon.closeAllPaths();
	String json = GeometryEngine.geometryToJson(srIn, polygon);
	return spatial.fromJson(json);
}
 
Example 20
Source File: LatLongProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 4 votes vote down vote up
private Geometry findBoundingBox(String mgrs, int accuracy, Point mgrsPt)
{
	String mgrsZone = mgrs.substring(0, 1);
	int wkid = 0;
	String utm = null;
	if(mgrsZone.equals("A") || mgrsZone.equals("B") )
	{
		wkid = 32761;
	}
	else if(mgrsZone.equals("Y") || mgrsZone.equals("Z"))
	{
		wkid = 32661;
	}
	else
	{
		PeGeogcs peGeoCS = PeFactory.geogcs(4326);
		double[] coordArray = {mgrsPt.getX(), mgrsPt.getY()};
		String[] utmArray = new String[1];
		PeNotationUtm.geog_to_utm(peGeoCS, 1, coordArray, PeNotationUtm.PE_UTM_OPTS_NS, utmArray);
		utm=utmArray[0];
		wkid=GetWkidFromUTM(utm);
		
	}
	SpatialReference pcs = SpatialReference.create(wkid);
	SpatialReference gcs = SpatialReference.create(4326);
	Geometry projGeo = GeometryEngine.project(mgrsPt, gcs, pcs);//projec local
	Point projPt = (Point)projGeo;
	double dist = getDistFromAccuracy(accuracy);
	double xmin, ymin, xmax, ymax;
	xmin=projPt.getX();
	ymin=projPt.getY();
	xmax = xmin + dist;
	ymax = ymin + dist;
	Polygon pbb = new Polygon();
	pbb.startPath(xmin, ymin);
	pbb.lineTo(xmax, ymin);
	pbb.lineTo(xmax, ymax);
	pbb.lineTo(xmin, ymax);
	pbb.lineTo(xmin, ymin);
	pbb.closeAllPaths();
	Geometry bb = GeometryEngine.project(pbb, pcs, gcs);//project back to wgs84
	return bb;
}