Java Code Examples for com.esri.core.geometry.GeometryEngine#project()
The following examples show how to use
com.esri.core.geometry.GeometryEngine#project() .
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: QueryReportProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 6 votes |
private com.esri.core.geometry.Geometry constructGeometry(com.esri.ges.spatial.Geometry geo) throws Exception { try{ String jsonIn = geo.toJson(); JsonFactory jf = new JsonFactory(); JsonParser jp = jf.createJsonParser(jsonIn); MapGeometry mgeo = GeometryEngine.jsonToGeometry(jp); com.esri.core.geometry.Geometry geoIn= mgeo.getGeometry(); return GeometryEngine.project(geoIn, srIn, srBuffer); } catch(Exception e) { LOG.error(e.getMessage()); LOG.error(e.getStackTrace()); throw(e); } }
Example 2
Source File: GeoJsonParser.java From arcgis-runtime-demo-java with Apache License 2.0 | 6 votes |
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 3
Source File: BufferProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 6 votes |
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 4
Source File: BufferProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 6 votes |
private Geometry constructBuffer(double x, double y, double radius, String units, 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(); String c_name = uc.findConnonicalName(units); int unitout = uc.findWkid(c_name); Unit u = LinearUnit.create(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 bufferout; }
Example 5
Source File: DemoTheatreApp.java From arcgis-runtime-demo-java with Apache License 2.0 | 6 votes |
/** * 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 6
Source File: LocalGeofence.java From arcgis-runtime-demos-android with Apache License 2.0 | 6 votes |
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 7
Source File: DemoTheatreAppImproved.java From arcgis-runtime-demo-java with Apache License 2.0 | 6 votes |
/** * 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 8
Source File: EllipseProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 6 votes |
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 9
Source File: QueryReportProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
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 10
Source File: ArcGISMapModule.java From react-native-arcgis-sdk-demo with Apache License 2.0 | 5 votes |
@ReactMethod public void setCenterWGS84(float x, float y) { Log.v(REACT_CLASS, "set center: " + x + ", " + y); if (mapView != null) { Point pointWgs = new Point(x, y); Point pointMap = (Point) GeometryEngine.project( pointWgs, SpatialReference.create(4326), mapView.getSpatialReference() ); mapView.centerAt(pointMap, true); } }
Example 11
Source File: SpatialQProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
private MapGeometry constructBuffer(Geometry geo, double radius, Unit u) throws JsonParseException, IOException { Polygon buffer = GeometryEngine.buffer(inGeometry, srBuffer, radius, u); Geometry bufferout = GeometryEngine.project(buffer, srBuffer, srOut); MapGeometry mapGeo = new MapGeometry(bufferout, srOut); return mapGeo; }
Example 12
Source File: BearingProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
private MapGeometry GenerateGeometry(Double ox, Double oy, Double dx, Double dy, SpatialReference srin, SpatialReference srout) { Point origin = new Point(); Point destination = new Point(); origin.setXY(ox, oy); destination.setXY(dx, dy); Polyline ln = new Polyline(); ln.startPath(origin); ln.lineTo(destination); MapGeometry tmp_mapGeo = new MapGeometry(ln, srin); Geometry projected = GeometryEngine.project(tmp_mapGeo.getGeometry(), srin, srout); MapGeometry mapGeo = new MapGeometry(projected, srout); return mapGeo; }
Example 13
Source File: GeoJsonParser.java From arcgis-runtime-demo-java with Apache License 2.0 | 5 votes |
private List<Geometry> parseGeometries(ArrayNode jsonGeometries) { List<Geometry> geometries = new LinkedList<Geometry>(); for (JsonNode jsonGeometry : jsonGeometries) { Geometry g = parseGeometry(jsonGeometry); if (outSR != null && outSR.getID() != 4326) { g = GeometryEngine.project(g, inSR, outSR); } geometries.add(g); } return geometries; }
Example 14
Source File: QueryReportProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
private Geometry constructGeometry(MapGeometry geo) throws Exception { try{ Geometry geoIn= geo.getGeometry(); return GeometryEngine.project(geoIn, srIn, srBuffer); } catch(Exception e) { LOG.error(e.getMessage()); LOG.error(e.getStackTrace()); throw(e); } }
Example 15
Source File: RangeFanProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
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 16
Source File: MapController.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
public void onLocationChanged(Location location) { if (null != location) { final Point mapPoint = GeometryEngine.project(location.getLongitude(), location.getLatitude(), getSpatialReference()); new Thread() { public void run() { synchronized (lastLocationLock) { lastLocation = mapPoint; } }; }.start(); if (isAutoPan()) { map.panTo(mapPoint); switch (getLocationController().getNavigationMode()) { case NORTH_UP: setRotation(0); break; case TRACK_UP: setRotation(location.getHeading()); break; case WAYPOINT_UP: Graphic waypoint = ((LocationController) getLocationController()).getSelectedWaypoint(); if (null != waypoint) { Point waypointLonLat = (Point) GeometryEngine.project( waypoint.getGeometry(), null == waypoint.getSpatialReference() ? getSpatialReference() : waypoint.getSpatialReference(), Utilities.WGS84); setRotation(Utilities.calculateBearingDegrees(location.getLongitude(), location.getLatitude(), waypointLonLat.getX(), waypointLonLat.getY())); } } } } }
Example 17
Source File: MapController.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 4 votes |
@Override public double[] projectPoint(double x, double y, int fromWkid, int toWkid) { Point pt = (Point) GeometryEngine.project(new Point(x, y), SpatialReference.create(fromWkid), SpatialReference.create(toWkid)); return new double[] { pt.getX(), pt.getY() }; }
Example 18
Source File: DemoTheatreAppImproved.java From arcgis-runtime-demo-java with Apache License 2.0 | 4 votes |
private void executeDriveTimes(Graphic startPointGraphic) { // create a Geoprocessor that points to the remote geoprocessing service. Geoprocessor geoprocessor = new Geoprocessor(URL_GEOPROCESSING_SERVICE); // set the output and process spatial reference to the map's spatial reference SpatialReference outSR = SpatialReference.create(4326); Geometry projectedStartPoint = GeometryEngine.project( startPointGraphic.getGeometry(), jMap.getSpatialReference(), outSR); Graphic projectedStartPointGraphic = new Graphic(projectedStartPoint, startPointGraphic.getSymbol()); geoprocessor.setOutSR(outSR); geoprocessor.setProcessSR(outSR); // initialize the required input parameters: refer to help link in the // geoprocessing service URL for a list of required parameters List<GPParameter> gpInputParams = new ArrayList<GPParameter>(); GPFeatureRecordSetLayer gpInputStartpoint = new GPFeatureRecordSetLayer("Input_Location"); gpInputStartpoint.addGraphic(projectedStartPointGraphic); //GPString gpInputDriveTimes = new GPString("Drive_Time"); // Tip: use GP service info to get the parameter names GPString gpInputDriveTimes = new GPString("Drive_Times"); gpInputDriveTimes.setValue("1 2 3"); gpInputParams.add(gpInputStartpoint); gpInputParams.add(gpInputDriveTimes); // execute the geoprocessing request /*try { GPParameter[] result = geoprocessor.execute(gpInputParams); updateProgresBarUI(null, tasksInProgress.decrementAndGet() > 0); processResult(result); } catch (Exception ex) { JOptionPane.showMessageDialog(map, ex.getMessage(), "", JOptionPane.ERROR_MESSAGE); }*/ // Tip: Do not block UI thread. geoprocessor.executeAsync( gpInputParams, new CallbackListener<GPParameter[]>() { @Override public void onError(Throwable th) { th.printStackTrace(); } @Override public void onCallback(GPParameter[] result) { updateProgresBarUI(null, tasksInProgress.decrementAndGet() > 0); processResult(result); } } ); }
Example 19
Source File: DemoTheatreApp.java From arcgis-runtime-demo-java with Apache License 2.0 | 4 votes |
private void executeDriveTimes(Graphic startPointGraphic) { // create a Geoprocessor that points to the remote geoprocessing service. Geoprocessor geoprocessor = new Geoprocessor(URL_GEOPROCESSING_SERVICE); // set the output and process spatial reference to the map's spatial reference SpatialReference outSR = SpatialReference.create(4326); Geometry projectedStartPoint = GeometryEngine.project( startPointGraphic.getGeometry(), jMap.getSpatialReference(), outSR); Graphic projectedStartPointGraphic = new Graphic(projectedStartPoint, startPointGraphic.getSymbol()); geoprocessor.setOutSR(outSR); geoprocessor.setProcessSR(outSR); // initialize the required input parameters: refer to help link in the // geoprocessing service URL for a list of required parameters List<GPParameter> gpInputParams = new ArrayList<GPParameter>(); GPFeatureRecordSetLayer gpInputStartpoint = new GPFeatureRecordSetLayer("Input_Location"); gpInputStartpoint.addGraphic(projectedStartPointGraphic); GPString gpInputDriveTimes = new GPString("Drive_Time"); // Tip: use GP service info to get the parameter names // GPString gpInputDriveTimes = new GPString("Drive_Times"); gpInputDriveTimes.setValue("1 2 3"); gpInputParams.add(gpInputStartpoint); gpInputParams.add(gpInputDriveTimes); // execute the geoprocessing request try { GPParameter[] result = geoprocessor.execute(gpInputParams); updateProgresBarUI(null, tasksInProgress.decrementAndGet() > 0); processResult(result); } catch (Exception ex) { JOptionPane.showMessageDialog(map, ex.getMessage(), "", JOptionPane.ERROR_MESSAGE); } /*// Tip: Do not block UI thread. geoprocessor.executeAsync( gpInputParams, new CallbackListener<GPParameter[]>() { @Override public void onError(Throwable th) { th.printStackTrace(); } @Override public void onCallback(GPParameter[] result) { updateProgresBarUI(null, tasksInProgress.decrementAndGet() > 0); processResult(result); } } ); */ }
Example 20
Source File: IdentifyResultsJPanel.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 4 votes |
/** * Shows the panel with the current result. */ public void showCurrentResult() { if (-1 != identifyFeatureGraphicUid) { graphicsLayer.removeGraphic(identifyFeatureGraphicUid); } jPanel_results.removeAll(); Geometry geom = null; if (null == results || 0 >= results.length) { jLabel_counter.setText("0 of 0"); jLabel_resultName.setText(""); jLabel_distance.setText("Distance:"); jLabel_bearing.setText("Bearing:"); } else { if (results.length <= currentIndex) { currentIndex = 0; } else if (0 > currentIndex) { currentIndex = results.length - 1; } jLabel_counter.setText((currentIndex + 1) + " of " + results.length); final IdentifiedItem result = results[currentIndex]; geom = result.getGeometry(); //Get attachments, if they are available Layer resultLayer = (null == resultToLayer ? null : resultToLayer.get(result)); final ArcGISFeatureLayer featureLayer = mapController.getFeatureLayer(resultLayer, result.getLayerId()); if (null != featureLayer && featureLayer.hasAttachments()) { featureLayer.queryAttachmentInfos(Integer.parseInt((String) result.getAttributes().get(featureLayer.getObjectIdField())), new CallbackListener<AttachmentInfo[]>() { public void onCallback(AttachmentInfo[] attachmentInfos) { finishShowingResult(result, attachmentInfos, featureLayer); } public void onError(Throwable e) { finishShowingResult(result); } }); } else { finishShowingResult(result); } } //Show distance and bearing from GPS location if available synchronized (gpsLocationLatLonLock) { boolean showedDistanceAndBearing = false; if (null != gpsLocationLatLon) { //Show them Point destinationMap = (geom instanceof Point) ? ((Point) geom) : identifyPoint; Point gpsLocationMap = (Point) GeometryEngine.project(gpsLocationLatLon, Utilities.WGS84, mapController.getSpatialReference()); double distance = Math.sqrt(Math.pow(destinationMap.getX() - gpsLocationMap.getX(), 2.0) + Math.pow(destinationMap.getY() - gpsLocationMap.getY(), 2.0)); Point destinationLatLon = (Point) GeometryEngine.project(destinationMap, mapController.getSpatialReference(), Utilities.WGS84); double bearing = Utilities.calculateBearingDegrees(gpsLocationLatLon, destinationLatLon); jLabel_distance.setText("Distance: " + Math.round(distance) + " " + mapController.getSpatialReference().getUnit().getAbbreviation()); jLabel_bearing.setText("Bearing: " + Math.round(bearing) + "\u00B0"); showedDistanceAndBearing = true; } if (!showedDistanceAndBearing) { jLabel_distance.setText(""); jLabel_bearing.setText(""); } } }