com.esri.core.geometry.GeometryEngine Java Examples

The following examples show how to use com.esri.core.geometry.GeometryEngine. 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: EllipseProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private MapGeometry constructEllipse(double x, double y, double majorAxis, double minorAxis, double rotation, int wkidin, int wkidbuffer, int wkidout)
{
	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);
	UnitConverter uc = new UnitConverter();
	majorAxis = uc.Convert(majorAxis, units, srBuffer);
	minorAxis = uc.Convert(minorAxis, units, srBuffer);
	Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer);
	GeometryUtility geoutil = new GeometryUtility();
	Polygon ellipse = geoutil.GenerateEllipse(centerProj, majorAxis, minorAxis, rotation);
	Geometry ellipseOut = GeometryEngine.project(ellipse, srBuffer, srOut);
	MapGeometry mapGeo = new MapGeometry(ellipseOut, srOut);
	return mapGeo;
}
 
Example #2
Source File: AdvancedSymbolController.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
@Override
protected Integer displaySpotReport(double x, double y, final int wkid, Integer graphicId, Geomessage geomessage) {
    try {
        Geometry pt = new Point(x, y);
        if (null != mapController.getSpatialReference() && wkid != mapController.getSpatialReference().getID()) {
            pt = GeometryEngine.project(pt, SpatialReference.create(wkid), mapController.getSpatialReference());
        }
        if (null != graphicId) {
            spotReportLayer.updateGraphic(graphicId, pt);
            spotReportLayer.updateGraphic(graphicId, geomessage.getProperties());
        } else {
            Graphic graphic = new Graphic(pt, spotReportSymbol, geomessage.getProperties());
            graphicId = spotReportLayer.addGraphic(graphic);
            
        }
        return graphicId;
    } catch (NumberFormatException nfe) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Could not parse spot report", nfe);
        return null;
    }
}
 
Example #3
Source File: TestStGeomFromShape.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testGeomFromPolylineShape() throws UDFArgumentException {
	Polyline line = createPolyline();
	byte[] esriShape = GeometryEngine.geometryToEsriShape(line);
	assertNotNull("The shape must not be null!", esriShape);

	BytesWritable shapeAsWritable = new BytesWritable(esriShape);
	assertNotNull("The shape writable must not be null!", shapeAsWritable);

	final int wkid = 4326;
	ST_GeomFromShape fromShape = new ST_GeomFromShape();
	BytesWritable geometryAsWritable = fromShape.evaluate(shapeAsWritable, wkid);
	assertNotNull("The geometry writable must not be null!", geometryAsWritable);

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryAsWritable);
	assertNotNull("The OGC geometry must not be null!", ogcGeometry);

	Geometry esriGeometry = ogcGeometry.getEsriGeometry();
	assertNotNull("The Esri geometry must not be null!", esriGeometry);
	assertTrue("The geometries are different!",
			GeometryEngine.equals(line, esriGeometry, SpatialReference.create(wkid)));
}
 
Example #4
Source File: TestStGeomFromShape.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testGeomFromPolygonShape() throws UDFArgumentException {
	Polygon polygon = createPolygon();
	byte[] esriShape = GeometryEngine.geometryToEsriShape(polygon);
	assertNotNull("The shape must not be null!", esriShape);

	BytesWritable shapeAsWritable = new BytesWritable(esriShape);
	assertNotNull("The shape writable must not be null!", shapeAsWritable);

	final int wkid = 4326;
	ST_GeomFromShape fromShape = new ST_GeomFromShape();
	BytesWritable geometryAsWritable = fromShape.evaluate(shapeAsWritable, wkid);
	assertNotNull("The geometry writable must not be null!", geometryAsWritable);

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryAsWritable);
	assertNotNull("The OGC geometry must not be null!", ogcGeometry);

	Geometry esriGeometry = ogcGeometry.getEsriGeometry();
	assertNotNull("The Esri geometry must not be null!", esriGeometry);
	assertTrue("The geometries are different!",
			GeometryEngine.equals(polygon, esriGeometry, SpatialReference.create(wkid)));
}
 
Example #5
Source File: MgrsLayerController.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
/**
 * Tells the controller to display the given point.
 * @param pt the point to display.
 * @param sr the spatial reference of the point to display.
 */
public void showPoint(Point pt, SpatialReference sr) {
    synchronized (graphicUpdateLock) {
        lastPointShownLatLon = (Point) GeometryEngine.project(pt, sr, Utilities.WGS84);
        if (-1 == pointGraphicId) {
            createPointGraphic(pt);
            createTextGraphics(pt);
        } else {
            updateGraphic(pointGraphicId, pt);
            updateTextGraphics(pt);
            updateTextGraphics(getDistanceBearingString(currentGpsPointLatLon, lastPointShownLatLon));
        }
    }
    
    setLayerVisibility(true);
    moveLayerToTop();
}
 
Example #6
Source File: TestStGeomFromShape.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testGeomFromPointShape() throws UDFArgumentException {
	Point point = createFirstLocation();
	byte[] esriShape = GeometryEngine.geometryToEsriShape(point);
	assertNotNull("The shape must not be null!", esriShape);

	BytesWritable shapeAsWritable = new BytesWritable(esriShape);
	assertNotNull("The shape writable must not be null!", shapeAsWritable);

	final int wkid = 4326;
	ST_GeomFromShape fromShape = new ST_GeomFromShape();
	BytesWritable geometryAsWritable = fromShape.evaluate(shapeAsWritable, wkid);
	assertNotNull("The geometry writable must not be null!", geometryAsWritable);

	validatePoint(point, wkid, geometryAsWritable);
}
 
Example #7
Source File: BufferProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private com.esri.ges.spatial.Geometry constructBuffer(double x, double y, double radius, String units, int wkidin, int wkidbuffer, int wkidout) throws GeometryException
{
	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);
	UnitConverter uc = new UnitConverter();
	String c_name = uc.findConnonicalName(units);
	int unitout = uc.findWkid(c_name);
	Unit  u = new LinearUnit(unitout);
	Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer);
	Geometry buffer = GeometryEngine.buffer(centerProj, srBuffer, radius, u);
	Geometry bufferout = GeometryEngine.project(buffer, srBuffer, srOut);
	String json = GeometryEngine.geometryToJson(srOut, bufferout);
	return spatial.fromJson(json);
	
}
 
Example #8
Source File: ST_AsJson.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public Text evaluate(BytesWritable geomref){
	if (geomref == null || geomref.getLength() == 0){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref);
	if (ogcGeometry == null){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	Geometry esriGeom = ogcGeometry.getEsriGeometry();
	int wkid = GeometryUtils.getWKID(geomref);
	return new Text(GeometryEngine.geometryToJson(wkid, esriGeom));
}
 
Example #9
Source File: ST_AsText.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public Text evaluate(BytesWritable geomref){
	if (geomref == null || geomref.getLength() == 0){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref);
	if (ogcGeometry == null){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}
	
	int wktExportFlag = getWktExportFlag(GeometryUtils.getType(geomref));
	
	try {
		// mind: GeometryType with ST_AsText(ST_GeomFromText('MultiLineString((0 80, 0.03 80.04))'))
		// return new Text(ogcGeometry.asText());
		return new Text(GeometryEngine.geometryToWkt(ogcGeometry.getEsriGeometry(), wktExportFlag));
	} catch (Exception e){
		LOG.error(e.getMessage());
		return null;
	}
}
 
Example #10
Source File: DemoTheatreAppImproved.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Process result from geoprocessing execution.
 * 
 * @param result output of geoprocessing execution.
 */
private void processResult(GPParameter[] result) {
  for (GPParameter outputParameter : result) {
    if (outputParameter instanceof GPFeatureRecordSetLayer) {
      GPFeatureRecordSetLayer gpLayer = (GPFeatureRecordSetLayer) outputParameter;
      int zone = 0;
      // get all the graphics and add them to the graphics layer.
      // there will be one graphic per zone.
      for (Graphic graphic : gpLayer.getGraphics()) {
        SpatialReference fromSR = SpatialReference.create(4326);
        Geometry g = graphic.getGeometry();
        Geometry pg = GeometryEngine.project(g, fromSR, jMap.getSpatialReference());
        Graphic theGraphic = new Graphic(pg, zoneFillSymbols[zone++]);
        // add to the graphics layer
        graphicsLayer.addGraphic(theGraphic);
      }
    }
  }
}
 
Example #11
Source File: DemoTheatreApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private void highlightGeometry(Point point) {
  if (point == null) {
    return;
  }

  graphicsLayer.removeAll();
  graphicsLayer.addGraphic(
    new Graphic(point, new SimpleMarkerSymbol(Color.CYAN, 20, SimpleMarkerSymbol.Style.CIRCLE)));
  
  // -----------------------------------------------------------------------------------------
  // Zoom to the highlighted graphic
  // -----------------------------------------------------------------------------------------
  Geometry geometryForZoom = GeometryEngine.buffer(
    point, 
    map.getSpatialReference(), 
    map.getFullExtent().getWidth() * 0.10, 
    map.getSpatialReference().getUnit());
  map.zoomTo(geometryForZoom);
}
 
Example #12
Source File: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private List<Feature> parseFeatures(ArrayNode jsonFeatures) {
  List<Feature> features = new LinkedList<Feature>();
  for (JsonNode jsonFeature : jsonFeatures) {
    String type = jsonFeature.path(FIELD_TYPE).getTextValue();
    if (!FIELD_FEATURE.equals(type)) {
      continue;
    }
    Geometry g = parseGeometry(jsonFeature.path(FIELD_GEOMETRY));
    if (outSR != null && outSR.getID() != 4326) {
      g = GeometryEngine.project(g, inSR, outSR);
    }
    Map<String, Object> attributes = parseProperties(jsonFeature.path(FIELD_PROPERTIES));
    Feature f = new Graphic(g, symbol, attributes);
    features.add(f);
  } 
  return features; 
}
 
Example #13
Source File: RoadTest.java    From barefoot with Apache License 2.0 6 votes vote down vote up
@Test
public void testJSON() throws JSONException {
    String wkt = "LINESTRING(11.3136273 48.0972002,11.3138846 48.0972999)";
    BaseRoad osm = new BaseRoad(0L, 1L, 2L, 4L, true, (short) 5, 5.1F, 6.1F, 6.2F, 7.1F,
            (Polyline) GeometryEngine.geometryFromWkt(wkt, WktImportFlags.wktImportDefaults,
                    Geometry.Type.Polyline));

    Road road = new Road(osm, Heading.forward);
    RoadMap map = new RoadMap();
    map.add(road);

    String json = road.toJSON().toString();
    Road road2 = Road.fromJSON(new JSONObject(json), map);

    assertEquals(road, road2);
}
 
Example #14
Source File: MatcherKState.java    From barefoot with Apache License 2.0 6 votes vote down vote up
/**
 * Gets {@link JSONArray} of {@link MatcherKState} with map matched positions, represented by
 * road id and fraction, and the geometry of the routes.
 *
 * @return {@link JSONArray} of {@link MatcherKState} with map matched positions, represented by
 *         road id and fraction, and the geometry of the routes.
 * @throws JSONException thrown on JSON extraction or parsing error.
 */
public JSONArray toSlimJSON() throws JSONException {
    JSONArray json = new JSONArray();
    if (this.sequence() != null) {
        for (MatcherCandidate candidate : this.sequence()) {
            JSONObject jsoncandidate = candidate.point().toJSON();
            if (candidate.transition() != null) {
                jsoncandidate.put("route",
                        GeometryEngine.geometryToWkt(candidate.transition().route().geometry(),
                                WktExportFlags.wktExportLineString));
            }
            json.put(jsoncandidate);
        }
    }
    return json;
}
 
Example #15
Source File: PostGISReaderTest.java    From barefoot with Apache License 2.0 6 votes vote down vote up
@Test
public void testExclusion() throws IOException, JSONException {
    Properties properties = new Properties();
    properties.load(new FileInputStream("config/oberbayern.properties"));
    RoadReader reader = Loader.reader(properties);
    Polygon polygon = (Polygon) GeometryEngine.geometryFromWkt(
            "POLYGON ((11.40848 47.93157, 11.45109 47.93157,11.45109 47.89296,11.40848 47.89296,11.40848 47.93157))",
            WktImportFlags.wktImportDefaults, Type.Polygon);
    HashSet<Short> exclusion = new HashSet<>(Arrays.asList((short) 117));
    BaseRoad road = null;

    reader.open(polygon, exclusion);
    int count = 0;

    while ((road = reader.next()) != null) {
        assertTrue(
                GeometryEngine.overlaps(polygon, road.geometry(), SpatialReference.create(4326))
                        || GeometryEngine.contains(polygon, road.geometry(),
                                SpatialReference.create(4326)));
        assertTrue(!exclusion.contains(road.type()));
        count += 1;
    }

    reader.close();
    assertTrue(count > 0);
}
 
Example #16
Source File: DemoTheatreApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Process result from geoprocessing execution.
 * 
 * @param result output of geoprocessing execution.
 */
private void processResult(GPParameter[] result) {
  for (GPParameter outputParameter : result) {
    if (outputParameter instanceof GPFeatureRecordSetLayer) {
      GPFeatureRecordSetLayer gpLayer = (GPFeatureRecordSetLayer) outputParameter;
      int zone = 0;
      // get all the graphics and add them to the graphics layer.
      // there will be one graphic per zone.
      for (Graphic graphic : gpLayer.getGraphics()) {
        SpatialReference fromSR = SpatialReference.create(4326);
        Geometry g = graphic.getGeometry();
        Geometry pg = GeometryEngine.project(g, fromSR, jMap.getSpatialReference());
        Graphic theGraphic = new Graphic(pg, zoneFillSymbols[zone++]);
        // add to the graphics layer
        graphicsLayer.addGraphic(theGraphic);
      }
    }
  }
}
 
Example #17
Source File: LocalGeofence.java    From arcgis-runtime-demos-android with Apache License 2.0 6 votes vote down vote up
public static void setFence(Polygon newFence, SpatialReference fenceSpatialReference) {

    // Keep the original geometries.
    mFenceSr = fenceSpatialReference;
    mFence = newFence;

    // Work with the fence in WGS84, as that's what the location updates will be in.
    // Note that transformations could be used here to increase accuracy.
    if ( mFenceSr.getID() != mWgs84Sr.getID() ) {
      Geometry densified = GeometryEngine.geodesicDensifyGeometry(mFence,
          mFenceSr, 20, null);
      mFenceWgs84 = (Polygon)GeometryEngine.project(densified, mFenceSr, mWgs84Sr);
    }
    else {
      mFenceWgs84 = mFence;
    }
  }
 
Example #18
Source File: GeographyTest.java    From barefoot with Apache License 2.0 5 votes vote down vote up
@Test
public void testPathInterception1() {
    String point = "POINT(11.410624 48.144161)";
    String line =
            "LINESTRING(11.4047013 48.1402147,11.4047038 48.1402718,11.4047661 48.1403687,11.4053519 48.141055,11.4054617 48.1411901,11.4062664 48.1421968,11.4064586 48.1424479,11.4066449 48.1427372,11.4067254 48.1429028,11.4067864 48.1430673,11.4068647 48.1433303,11.4069456 48.1436822,11.4070524 48.1440368,11.4071569 48.1443314,11.4072635 48.1445915,11.4073887 48.1448641,11.4075228 48.1450729,11.407806 48.1454843,11.4080135 48.1458112,11.4083012 48.1463167,11.4086211 48.1469061,11.4087461 48.1471386,11.4088719 48.1474078,11.4089422 48.1476014,11.409028 48.1478353,11.409096 48.1480701,11.4091568 48.1483459,11.4094282 48.1498536)";

    Point c = (Point) GeometryEngine.geometryFromWkt(point, WktImportFlags.wktImportDefaults,
            Type.Point);
    Polyline ab = (Polyline) GeometryEngine.geometryFromWkt(line,
            WktImportFlags.wktImportDefaults, Type.Polyline);

    sw1.start();
    double f = spatial.intercept(ab, c);
    sw1.stop();

    double l = spatial.length(ab);

    sw2.start();
    Point p = spatial.interpolate(ab, l, f);
    sw2.stop();

    double d = spatial.distance(p, c);

    assertEquals(p.getX(), 11.407547966254612, 10E-6);
    assertEquals(p.getY(), 48.14510945890138, 10E-6);
    assertEquals(f, 0.5175157549609246, 10E-6);
    assertEquals(l, 1138.85464239099, 10E-6);
    assertEquals(d, 252.03375312704165, 10E-6);

    if (benchmark) {
        System.out.println("[Geography] path interception " + sw1.us()
                + " us (gnomonic), path interpolation " + sw2.us() + " us (geodesic)");
    }
}
 
Example #19
Source File: OGCGeometry.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
public boolean crosses(OGCGeometry another) {
	if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) {
		//TODO
		throw new UnsupportedOperationException();
	}
	
	com.esri.core.geometry.Geometry geom1 = getEsriGeometry();
	com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry();
	return com.esri.core.geometry.GeometryEngine.crosses(geom1, geom2,
			getEsriSpatialReference());
}
 
Example #20
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 #21
Source File: GeometryOnlineApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseClicked(MouseEvent event) {
  graphicsLayer.removeAll();

  // add buffer as a graphic
  Point mapPoint = map.toMapPoint(event.getX(), event.getY());
  final Geometry buffer = GeometryEngine.buffer(
      mapPoint, map.getSpatialReference(), 200000, map.getSpatialReference().getUnit());
  graphicsLayer.addGraphic(new Graphic(buffer, new SimpleFillSymbol(new Color(255, 0, 0, 255))));

  // get states at the buffered area
  QueryTask queryTask = new QueryTask(featureLayer.getUrl());
  QueryParameters queryParams = new QueryParameters();
  queryParams.setInSpatialReference(map.getSpatialReference());
  queryParams.setOutSpatialReference(map.getSpatialReference());
  queryParams.setGeometry(buffer);
  queryParams.setReturnGeometry(true);
  queryParams.setOutFields(new String[] {"STATE_NAME"});

  queryTask.execute(queryParams, new CallbackListener<FeatureResult>() {

    @Override
    public void onError(Throwable arg0) {
      // deal with any exception
    }

    @Override
    public void onCallback(FeatureResult result) {
      for (Object objFeature : result) {
        Feature feature = (Feature) objFeature;
        graphicsLayer.addGraphic(new Graphic(feature.getGeometry(), stateSymbol));
        graphicsLayer.addGraphic(new Graphic(buffer, new SimpleFillSymbol(new Color(255, 0, 0, 255))));


      }
    }
  });
}
 
Example #22
Source File: MatcherKState.java    From barefoot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets JSON format String of {@link MatcherKState}, includes {@link JSONArray} String of
 * samples and {@link JSONArray} String of of matching results.
 *
 * @return JSON format String of {@link MatcherKState}, includes {@link JSONArray} String of
 *         samples and {@link JSONArray} String of of matching results.
 * @throws JSONException thrown on JSON extraction or parsing error.
 */
public String toDebugJSON() throws JSONException {
    StringBuilder output = new StringBuilder();

    JSONArray jsonsamples = new JSONArray();
    if (this.samples() != null) {
        for (int i = 0; i < this.samples().size(); ++i) {
            JSONObject jsonsample = new JSONObject();
            jsonsample.put("id", this.samples().get(i).id());
            jsonsample.put("geom", GeometryEngine.geometryToWkt(this.samples().get(i).point(),
                    WktExportFlags.wktExportPoint));
            jsonsample.put("time", this.samples().get(i).time() / 1000);
            jsonsamples.put(jsonsample);
        }
    }
    output.append(jsonsamples.toString());
    output.append("\n");

    JSONArray jsonsequence = new JSONArray();
    if (this.sequence() != null) {
        for (int i = 0; i < this.sequence().size(); ++i) {
            MatcherCandidate candidate = this.sequence().get(i);
            JSONObject jsoncandidate = candidate.toJSON();
            jsoncandidate.put("time", this.samples().get(i).time() / 1000);
            if (candidate.transition() != null) {
                jsoncandidate.put("geom",
                        GeometryEngine.geometryToWkt(candidate.transition().route().geometry(),
                                WktExportFlags.wktExportLineString));
            } else {
                jsoncandidate.put("geom", GeometryEngine.geometryToWkt(
                        candidate.point().geometry(), WktExportFlags.wktExportPoint));
            }
            jsonsequence.put(jsoncandidate);
        }
    }
    output.append(jsonsequence.toString());

    return output.toString();
}
 
Example #23
Source File: VisibilityProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private String ConstructJsonMaskFromGeoEvent(GeoEvent ge) throws IOException
{
	com.esri.ges.spatial.Geometry eventgeo = ge.getGeometry();
	String json = eventgeo.toJson();
	JsonFactory jf = new JsonFactory();
	JsonParser jp = jf.createJsonParser(json);
	MapGeometry mgeo = GeometryEngine.jsonToGeometry(jp);
	Geometry geo = mgeo.getGeometry();
	Geometry maskGeo = GeometryEngine.project(geo, srIn, srBuffer);
	return GeometryEngine.geometryToJson(srBuffer, maskGeo);
}
 
Example #24
Source File: OverlayApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseClicked(MouseEvent e) {
  Point pt = map.toMapPoint(e.getX(), e.getY());

  Geometry buffer = GeometryEngine.buffer(pt, map.getSpatialReference(), 200000, map.getSpatialReference().getUnit());

  Graphic g = new Graphic(buffer, bufferSymbol);
  graphicsLayer.addGraphic(g);
}
 
Example #25
Source File: MatcherKStateTest.java    From barefoot with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws SourceException {
    if (roads.isEmpty()) {
        for (Entry entry : entries) {
            Polyline geometry = (Polyline) GeometryEngine.geometryFromWkt(entry.five(),
                    WktImportFlags.wktImportDefaults, Type.Polyline);
            roads.add(new BaseRoad(entry.one(), entry.two(), entry.three(), entry.one(),
                    entry.four(), (short) 0, 1.0f, 100.0f, 100.0f,
                    (float) spatial.length(geometry), geometry));
        }
    }

    iterator = roads.iterator();
}
 
Example #26
Source File: OGCGeometry.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
public OGCGeometry difference(OGCGeometry another) {
	if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) {
		return (new OGCConcreteGeometryCollection(this, esriSR)).difference(another);
	}
	
	com.esri.core.geometry.Geometry geom1 = getEsriGeometry();
	com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry();
	return createFromEsriGeometry(
			com.esri.core.geometry.GeometryEngine.difference(geom1, geom2,
					getEsriSpatialReference()), esriSR);
}
 
Example #27
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private String GetDistAsString(Graphic g, SpatialReference inputSr, String units)
{
	com.esri.core.geometry.Geometry geo = g.getGeometry();
	com.esri.core.geometry.Geometry curGeo;
	
	if(!inputSr.equals(srBuffer))
	{
		curGeo = GeometryEngine.project(geo, inputSr, srBuffer);
	}
	else
	{
		curGeo=geo;
	}
	double tmpDist = GeometryEngine.distance(inGeometry, curGeo, srBuffer);
	UnitConverter uc = new UnitConverter();
	int inUnitWkid = uc.findWkid(srBuffer.getUnit().getName());
	String cn = uc.findConnonicalName(units);
	int outUnitWkid = uc.findWkid(cn);
	double dist;
	if(inUnitWkid!=outUnitWkid)
	{
		dist = uc.Convert(tmpDist, inUnitWkid, outUnitWkid);
	}
	else
	{
		dist=tmpDist;
	}
	
	DecimalFormat df = new DecimalFormat("#.00");
	return df.format(dist);
}
 
Example #28
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private String GetDistAsString(Map<String, Object> objGeo, SpatialReference inputSr, String units) throws JsonParseException, IOException
{
	Geometry geo = generateGeoFromMap(objGeo);
	com.esri.core.geometry.Geometry curGeo;
	
	if(!inputSr.equals(srBuffer))
	{
		curGeo = GeometryEngine.project(geo, inputSr, srBuffer);
	}
	else
	{
		curGeo=geo;
	}
	double tmpDist = GeometryEngine.distance(inGeometry, curGeo, srBuffer);
	UnitConverter uc = new UnitConverter();
	int inUnitWkid = uc.findWkid(srBuffer.getUnit().getName());
	String cn = uc.findConnonicalName(units);
	int outUnitWkid = uc.findWkid(cn);
	double dist;
	if(inUnitWkid!=outUnitWkid)
	{
		dist = uc.Convert(tmpDist, inUnitWkid, outUnitWkid);
	}
	else
	{
		dist=tmpDist;
	}
	
	DecimalFormat df = new DecimalFormat("#.00");
	return df.format(dist);
}
 
Example #29
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 constructBuffer(Geometry geo, double radius, Unit u) throws GeometryException, JsonParseException, IOException
{
	
	com.esri.core.geometry.Geometry buffer = GeometryEngine.buffer(inGeometry, srBuffer, radius, u);
	com.esri.core.geometry.Geometry bufferout = GeometryEngine.project(buffer, srBuffer, srOut);
	String json = GeometryEngine.geometryToJson(srOut, bufferout);
	return spatial.fromJson(json);
	
}
 
Example #30
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;
	}
}