Java Code Examples for com.esri.core.geometry.SpatialReference#create()
The following examples show how to use
com.esri.core.geometry.SpatialReference#create() .
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: 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 2
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 3
Source File: ST_PolyFromWKB.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException { try { SpatialReference spatialReference = null; if (wkid != GeometryUtils.WKID_UNKNOWN) { spatialReference = SpatialReference.create(wkid); } byte [] byteArr = wkb.getBytes(); ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length); byteBuf.put(byteArr); OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf); ogcObj.setSpatialReference(spatialReference); if (ogcObj.geometryType().equals("Polygon")) { return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj); } else { LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POLYGON, GeometryUtils.OGCType.UNKNOWN); return null; } } catch (Exception e) { // IllegalArgumentException, GeometryException LOG.error(e.getMessage()); return null; } }
Example 4
Source File: BufferProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 6 votes |
@Override public GeoEvent process(GeoEvent ge) throws Exception { // Operation phase... if (radius == null) { radius = (Double) ge.getField(bufferEventFld); if (radius == null) { Exception e = new Exception("Radius is not defined in geoevent"); throw (e); } } MapGeometry mapGeo = ge.getGeometry(); Point eventGeo = (Point) mapGeo.getGeometry(); double x = eventGeo.getX(); double y = eventGeo.getY(); int inwkid = mapGeo.getSpatialReference().getID(); //int inwkid = eventGeo.getSpatialReference().getWkid(); Geometry buffer = constructBuffer(x, y, radius, units, inwkid, bufferwkid, outwkid); SpatialReference srOut = SpatialReference.create(outwkid); MapGeometry outMapGeo = new MapGeometry(buffer, srOut); ge.setGeometry(outMapGeo); return ge; }
Example 5
Source File: ST_PointFromWKB.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException { try { SpatialReference spatialReference = null; if (wkid != GeometryUtils.WKID_UNKNOWN) { spatialReference = SpatialReference.create(wkid); } byte [] byteArr = wkb.getBytes(); ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length); byteBuf.put(byteArr); OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf); ogcObj.setSpatialReference(spatialReference); if (ogcObj.geometryType().equals("Point")) { return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj); } else { LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POINT, GeometryUtils.OGCType.UNKNOWN); return null; } } catch (Exception e) { // IllegalArgumentException, GeometryException LOG.error(e.getMessage()); return null; } }
Example 6
Source File: ST_GeomFromWKB.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException { try { SpatialReference spatialReference = null; if (wkid != GeometryUtils.WKID_UNKNOWN) { spatialReference = SpatialReference.create(wkid); } byte [] byteArr = wkb.getBytes(); ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length); byteBuf.put(byteArr); OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf); ogcObj.setSpatialReference(spatialReference); return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj); } catch (Exception e) { // IllegalArgumentException, GeometryException LOG.error(e.getMessage()); return null; } }
Example 7
Source File: ST_Envelope.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
public BytesWritable evaluate(BytesWritable geometryref) { if (geometryref == null || geometryref.getLength() == 0) { LogUtils.Log_ArgumentsNull(LOG); return null; } OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryref); if (ogcGeometry == null){ LogUtils.Log_ArgumentsNull(LOG); return null; } int wkid = GeometryUtils.getWKID(geometryref); SpatialReference spatialReference = null; if (wkid != GeometryUtils.WKID_UNKNOWN) { spatialReference = SpatialReference.create(wkid); } Envelope envBound = new Envelope(); ogcGeometry.getEsriGeometry().queryEnvelope(envBound); return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(envBound, spatialReference)); }
Example 8
Source File: ST_GeomCollection.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
public BytesWritable evaluate(Text wkwrap, int wkid) throws UDFArgumentException { String wkt = wkwrap.toString(); try { Geometry geomObj = GeometryEngine.geometryFromWkt(wkt, 0, Geometry.Type.Unknown); SpatialReference spatialReference = null; // Idea: OGCGeometry.setSpatialReference after .fromText if (wkid != GeometryUtils.WKID_UNKNOWN) { spatialReference = SpatialReference.create(wkid); } OGCGeometry ogcObj = OGCGeometry.createFromEsriGeometry(geomObj, spatialReference); return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj); } catch (Exception e) { // IllegalArgumentException, GeometryException LogUtils.Log_InvalidText(LOG, wkt); return null; } }
Example 9
Source File: ST_MLineFromWKB.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException { try { SpatialReference spatialReference = null; if (wkid != GeometryUtils.WKID_UNKNOWN) { spatialReference = SpatialReference.create(wkid); } byte [] byteArr = wkb.getBytes(); ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length); byteBuf.put(byteArr); OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf); ogcObj.setSpatialReference(spatialReference); String gType = ogcObj.geometryType(); if (gType.equals("MultiLineString") || gType.equals("LineString")) { return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj); } else { LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTILINESTRING, GeometryUtils.OGCType.UNKNOWN); return null; } } catch (Exception e) { // IllegalArgumentException, GeometryException LOG.error(e.getMessage()); return null; } }
Example 10
Source File: ST_MPointFromWKB.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
public BytesWritable evaluate(BytesWritable wkb, int wkid) throws UDFArgumentException { try { SpatialReference spatialReference = null; if (wkid != GeometryUtils.WKID_UNKNOWN) { spatialReference = SpatialReference.create(wkid); } byte [] byteArr = wkb.getBytes(); ByteBuffer byteBuf = ByteBuffer.allocate(byteArr.length); byteBuf.put(byteArr); OGCGeometry ogcObj = OGCGeometry.fromBinary(byteBuf); ogcObj.setSpatialReference(spatialReference); String gType = ogcObj.geometryType(); if (gType.equals("MultiPoint") || gType.equals("Point")) { return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj); } else { LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_LINESTRING, GeometryUtils.OGCType.UNKNOWN); return null; } } catch (Exception e) { // IllegalArgumentException, GeometryException LOG.error(e.getMessage()); return null; } }
Example 11
Source File: ST_EndPoint.java From spatial-framework-for-hadoop with Apache License 2.0 | 5 votes |
/** * Return the last point of the ST_Linestring. * @param geomref hive geometry bytes * @return byte-reference of the last ST_Point */ public BytesWritable 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; } if (GeometryUtils.getType(geomref) == GeometryUtils.OGCType.ST_LINESTRING) { MultiPath lines = (MultiPath)(ogcGeometry.getEsriGeometry()); int wkid = GeometryUtils.getWKID(geomref); SpatialReference spatialReference = null; if (wkid != GeometryUtils.WKID_UNKNOWN) { spatialReference = SpatialReference.create(wkid); } return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(lines.getPoint(lines.getPointCount()-1), spatialReference)); } else { LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_LINESTRING, GeometryUtils.getType(geomref)); return null; } }
Example 12
Source File: EllipseProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
private com.esri.ges.spatial.Geometry constructEllipse(double x, double y, double majorAxis, double minorAxis, double rotation, 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); 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); String json = GeometryEngine.geometryToJson(srOut, ellipseOut); return spatial.fromJson(json); }
Example 13
Source File: ST_StartPoint.java From spatial-framework-for-hadoop with Apache License 2.0 | 5 votes |
/** * Return the first point of the ST_Linestring. * @param geomref hive geometry bytes * @return byte-reference of the first ST_Point */ public BytesWritable 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; } if (GeometryUtils.getType(geomref) == GeometryUtils.OGCType.ST_LINESTRING) { MultiPath lines = (MultiPath)(ogcGeometry.getEsriGeometry()); int wkid = GeometryUtils.getWKID(geomref); SpatialReference spatialReference = null; if (wkid != GeometryUtils.WKID_UNKNOWN) { spatialReference = SpatialReference.create(wkid); } return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(lines.getPoint(0), spatialReference)); } else { LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_LINESTRING, GeometryUtils.getType(geomref)); return null; } }
Example 14
Source File: ST_Aggr_Intersection.java From spatial-framework-for-hadoop with Apache License 2.0 | 5 votes |
public boolean iterate(BytesWritable geomref) throws HiveException { if (geomref == null) { LogUtils.Log_ArgumentsNull(LOG); return false; } if (firstWKID == -2) { firstWKID = GeometryUtils.getWKID(geomref); if (firstWKID != GeometryUtils.WKID_UNKNOWN) { spatialRef = SpatialReference.create(firstWKID); } } else if (firstWKID != GeometryUtils.getWKID(geomref)) { LogUtils.Log_SRIDMismatch(LOG, geomref, firstWKID); return false; } try { OGCGeometry rowGeom = GeometryUtils.geometryFromEsriShape(geomref); rowGeom.setSpatialReference(spatialRef); if (isectGeom == null) isectGeom = rowGeom; else isectGeom = isectGeom.intersection(rowGeom); return true; } catch (Exception e) { LogUtils.Log_InternalError(LOG, "ST_Aggr_Intersection: " + e); return false; } }
Example 15
Source File: ST_Aggr_Union.java From spatial-framework-for-hadoop with Apache License 2.0 | 5 votes |
public boolean iterate(BytesWritable geomref) throws HiveException { if (geomref == null) { LogUtils.Log_ArgumentsNull(LOG); return false; } if (xgc == null) { firstWKID = GeometryUtils.getWKID(geomref); if (firstWKID != GeometryUtils.WKID_UNKNOWN) { spatialRef = SpatialReference.create(firstWKID); } // Need new geometry cursors both initially and after every terminatePartial(), // because the geometry cursors can not be re-used after extracting the // unioned geometry with GeometryCursor.next(). //Create an empty listener. lgc = new ListeningGeometryCursor(); //Obtain union operator - after taking note of spatial reference. xgc = OperatorUnion.local().execute(lgc, spatialRef, null); } else if (firstWKID != GeometryUtils.getWKID(geomref)) { LogUtils.Log_SRIDMismatch(LOG, geomref, firstWKID); return false; } try { lgc.tick(GeometryUtils.geometryFromEsriShape(geomref).getEsriGeometry()); // push xgc.tock(); // tock to match tick return true; } catch (Exception e) { LogUtils.Log_InternalError(LOG, "ST_Aggr_Union: " + e); return false; } }
Example 16
Source File: MapController.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
@Override public String pointToMgrs(double x, double y, int wkid) { Point pt = new Point(x, y); try { SpatialReference sr = SpatialReference.create(wkid); return pointToMgrs(pt, sr); } catch (Throwable t) { Logger.getLogger(MapController.class.getName()).log(Level.SEVERE, null, t); return null; } }
Example 17
Source File: PolygonProcessor.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
@Override public GeoEvent process(GeoEvent evt){ try { int inwkid = (Integer) properties.get("wkidin").getValue(); int outwkid = (Integer) properties.get("wkidout").getValue(); //int bufferwkid = (Integer) properties.get("wkidbuffer").getValue(); srIn = SpatialReference.create(inwkid); //srBuffer = SpatialReference.create(bufferwkid); srOut = SpatialReference.create(outwkid); String eventfld = properties.get("polyfld").getValue().toString(); String[] arr = eventfld.split(":"); String geostring = (String) evt.getField(arr[1]); String format = properties.get("polyformat").getValue().toString(); com.esri.ges.spatial.Geometry geo = null; if (format.equals("Json")) { geo = constructJsonGeometry(geostring); } else if (format.equals("CAP")) { geo = constructCAPGeometry(geostring); } evt.setGeometry(geo); return evt; } catch (Exception ex) { LOG.error(ex.getMessage()); LOG.error(ex.getStackTrace()); return null; } }
Example 18
Source File: ST_Union.java From spatial-framework-for-hadoop with Apache License 2.0 | 4 votes |
public BytesWritable evaluate (BytesWritable ... geomrefs){ // validate arguments if (geomrefs == null || geomrefs.length < 2){ LogUtils.Log_VariableArgumentLength(LOG); } int firstWKID = 0; SpatialReference spatialRef = null; // validate spatial references and geometries first for (int i=0;i<geomrefs.length; i++){ BytesWritable geomref = geomrefs[i]; if (geomref == null || geomref.getLength() == 0){ LogUtils.Log_ArgumentsNull(LOG); return null; } if (i==0){ firstWKID = GeometryUtils.getWKID(geomref); if (firstWKID != GeometryUtils.WKID_UNKNOWN) { spatialRef = SpatialReference.create(firstWKID); } } else if (firstWKID != GeometryUtils.getWKID(geomref)){ LogUtils.Log_SRIDMismatch(LOG, geomrefs[0], geomref); return null; } } // now build geometry array to pass to GeometryEngine.union Geometry [] geomsToUnion = new Geometry[geomrefs.length]; for (int i=0;i<geomrefs.length;i++){ //HiveGeometry hiveGeometry = GeometryUtils.geometryFromEsriShape(geomrefs[i]); OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomrefs[i]); // if (i==0){ // get from ogcGeometry rather than re-create above? // spatialRef = hiveGeometry.spatialReference; // } if (ogcGeometry == null){ LogUtils.Log_ArgumentsNull(LOG); return null; } geomsToUnion[i] = ogcGeometry.getEsriGeometry(); } try { Geometry unioned = GeometryEngine.union(geomsToUnion, spatialRef); // we have to infer the type of the differenced geometry because we don't know // if it's going to end up as a single or multi-part geometry OGCType inferredType = GeometryUtils.getInferredOGCType(unioned); return GeometryUtils.geometryToEsriShapeBytesWritable(unioned, firstWKID, inferredType); } catch (Exception e){ LogUtils.Log_ExceptionThrown(LOG, "GeometryEngine.union", e); return null; } }
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: 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); } } ); }