com.esri.core.geometry.SpatialReference Java Examples

The following examples show how to use com.esri.core.geometry.SpatialReference. 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: ST_LineFromWKB.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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("LineString")) {
				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 #2
Source File: ST_PolyFromWKB.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: MoreMapLayer.java    From arcgis-android-moremap with Apache License 2.0 6 votes vote down vote up
protected void initLayer() {
    if (getID() == 0L) {
        nativeHandle = create();
        changeStatus(com.esri.android.map.event.OnStatusChangedListener.STATUS
                .fromInt(-1000));
    } else {
        this.setDefaultSpatialReference(SpatialReference.create(layerInfo
                .getSrid()));
        this.setFullExtent(new Envelope(layerInfo.getxMin(), layerInfo
                .getyMin(), layerInfo.getxMax(), layerInfo.getyMax()));
        this.setTileInfo(new TileInfo(layerInfo.getOrigin(), layerInfo
                .getScales(), layerInfo.getResolutions(), layerInfo
                .getScales().length, layerInfo.getDpi(), layerInfo
                .getTileWidth(), layerInfo.getTileHeight()));
        super.initLayer();
    }
}
 
Example #4
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 #5
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 #6
Source File: ST_MPolyFromWKB.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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("MultiPolygon") || gType.equals("Polygon")) {
				return GeometryUtils.geometryToEsriShapeBytesWritable(ogcObj);
			} else {
				LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_MULTIPOLYGON, GeometryUtils.OGCType.UNKNOWN);
				return null;
			}
		} catch (Exception e) {  // IllegalArgumentException, GeometryException
			LOG.error(e.getMessage());
			return null;
		}
	}
 
Example #7
Source File: BufferProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
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 #8
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 #9
Source File: OGCGeometry.java    From geometry-api-java with Apache License 2.0 6 votes vote down vote up
public static OGCGeometry createFromEsriCursor(GeometryCursor gc,
		SpatialReference sr, boolean skipEmpty) {
	ArrayList<OGCGeometry> geoms = new ArrayList<OGCGeometry>(10);
	Geometry emptyGeom = null;
	for (Geometry g = gc.next(); g != null; g = gc.next()) {
		emptyGeom = g;
		if (!skipEmpty || !g.isEmpty())
			geoms.add(createFromEsriGeometry(g, sr));
	}

	if (geoms.size() == 1) {
		return geoms.get(0);
	} else if (geoms.size() == 0)
		return createFromEsriGeometry(emptyGeom, sr);
	else
		return new OGCConcreteGeometryCollection(geoms, sr);
}
 
Example #10
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 #11
Source File: ST_MLineFromWKB.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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 #12
Source File: ST_Aggr_ConvexHull.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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;
			}

			addGeometryToBuffer(geomref);

			return (geometries.size() != 0);
		}
 
Example #13
Source File: ST_MPointFromWKB.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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 #14
Source File: ST_PointFromWKB.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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 #15
Source File: ST_Envelope.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
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 #16
Source File: PostGISReaderTest.java    From barefoot with Apache License 2.0 6 votes vote down vote up
@Test
public void testPolygon() 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);
    BaseRoad road = null;

    reader.open(polygon, null);
    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)));
        count += 1;
    }

    reader.close();
    assertTrue(count > 0);
}
 
Example #17
Source File: BufferProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
@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 #18
Source File: ST_StartPoint.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #19
Source File: GeoFunctions.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Computes the union of the geometries in {@code geomCollection}. */
@SemiStrict public static Geom ST_Union(Geom geomCollection) {
  SpatialReference sr = geomCollection.sr();
  final Geometry g =
      GeometryEngine.union(new Geometry[] {geomCollection.g()}, sr);
  return bind(g, sr);
}
 
Example #20
Source File: OGCConcreteGeometryCollection.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Override
public void setSpatialReference(SpatialReference esriSR_) {
	esriSR = esriSR_;
	for (int i = 0, n = geometries.size(); i < n; i++) {
		if (geometries.get(i) != null)
			geometries.get(i).setSpatialReference(esriSR_);
	}
}
 
Example #21
Source File: GeoFunctions.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Returns whether {@code geom1} intersects {@code geom2}. */
public static boolean ST_Intersects(Geom geom1, Geom geom2)  {
  final Geometry g1 = geom1.g();
  final Geometry g2 = geom2.g();
  final SpatialReference sr = geom1.sr();
  return intersects(g1, g2, sr);
}
 
Example #22
Source File: MapController.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: ChemLightJPanel.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a ChemLightJPanel.
 * @param chemLightController the ChemLightController used to send messages to
 *        update and remove chem lights.
 * @param chemLight the chem light Graphic.
 * @param chemLightSpatialReference the spatial reference for the chem light
 *        Graphic's point geometry.
 */
public ChemLightJPanel(
        ChemLightController chemLightController,
        Graphic chemLight,
        SpatialReference chemLightSpatialReference) {
    initComponents();
    
    this.chemLightController = chemLightController;
    this.chemLight = chemLight;
    this.chemLightSR = chemLightSpatialReference;
}
 
Example #24
Source File: CAPInboundAdapter.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
public CAPInboundAdapter(AdapterDefinition definition) throws ComponentException
{
	super(definition);
	 MAP = new LinkedHashMap(MAX_ENTRIES + 1, 1.1f, false){protected boolean removeEldestEntry(Map.Entry eldest){return size() > MAX_ENTRIES;}};
	 arcgisWGS = com.esri.core.geometry.SpatialReference.create(4326);
	 arcgisKmUnit = com.esri.core.geometry.Unit.create(9036);
}
 
Example #25
Source File: OGCPolygon.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
public OGCPolygon(Polygon geom, SpatialReference sr) {
	polygon = geom;
	if (geom.getExteriorRingCount() > 1)
		throw new IllegalArgumentException(
				"Polygon has to have one exterior ring. Simplify geom with OperatorSimplify.");
	esriSR = sr;
}
 
Example #26
Source File: SpatialReferenceSerializer.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
Object readResolve() throws ObjectStreamException {
	SpatialReference sr = null;
	try {
		if (wkid > 0)
			sr = SpatialReference.create(wkid);
		else
			sr = SpatialReference.create(wkt);
	} catch (Exception ex) {
		throw new InvalidObjectException(
				"Cannot read spatial reference from stream");
	}
	return sr;
}
 
Example #27
Source File: GeoFunctions.java    From Quicksql with MIT License 5 votes vote down vote up
protected static Geom bind(Geometry geometry, int srid) {
  if (geometry == null) {
    return null;
  }
  if (srid == NO_SRID) {
    return new SimpleGeom(geometry);
  }
  return bind(geometry, SpatialReference.create(srid));
}
 
Example #28
Source File: UnitConverter.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
public double Convert(double v, String unitsin, SpatialReference srout)
{
	Unit u = srout.getUnit();
	String srcannonicalName = u.getName();
	int srwkid = findWkid(srcannonicalName);
	String cannonicalName = findConnonicalName(unitsin);
	int unitwkid = findWkid(cannonicalName);
	if(srwkid != unitwkid)
	{
		v = Convert(v, unitwkid, srwkid);
	}
	return v;
}
 
Example #29
Source File: UnitConverter.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
public double Convert(double v, String unitsin, SpatialReference srout)
{
	Unit u = srout.getUnit();
	String srcannonicalName = u.getName();
	int srwkid = findWkid(srcannonicalName);
	String cannonicalName = findConnonicalName(unitsin);
	int unitwkid = findWkid(cannonicalName);
	if(srwkid != unitwkid)
	{
		v = Convert(v, unitwkid, srwkid);
	}
	return v;
}
 
Example #30
Source File: MapController.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an MGRS string to a map point.
 * @param mgrsString the MGRS string to convert to a map point.
 * @return a map point in the coordinate system of the map.
 */
public Point mgrsToPoint(String mgrsString) {
    SpatialReference sr = map.getSpatialReference();
    if (null == sr) {
        //Assume Web Mercator (3857)
        sr = SpatialReference.create(3857);
    }
    return CoordinateConversion.mgrsToPoint(mgrsString, sr, CoordinateConversion.MGRSConversionMode.AUTO);
}