com.esri.core.geometry.MapGeometry Java Examples

The following examples show how to use com.esri.core.geometry.MapGeometry. 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 vote down vote up
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: 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 #3
Source File: Line2PtProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private GeoEvent createLine2PtGeoevent(GeoEvent event, MapGeometry outGeo, Date ts) throws MessagingException, FieldException
{
	GeoEventCreator creator = messaging.createGeoEventCreator();
	GeoEvent msg = creator.create(outDef, definition.getUri().toString());
	for(FieldDefinition fd: event.getGeoEventDefinition().getFieldDefinitions())
	{
		if(fd.getTags().contains("GEOMETRY"))
		{
			msg.setGeometry(outGeo);
		}
		else
		{
			msg.setField(fd.getName(), event.getField(fd.getName()));
		}
		msg.setField("TIMESTAMP", ts);

	}
	return msg;
}
 
Example #4
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 #5
Source File: TrackIdleProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private boolean hasGeometryMoved(MapGeometry geom1, MapGeometry geom2,
		double tolerance) {
	if (geom1 != null && geom1.getGeometry() != null
			&& geom1.getGeometry().getType() == Type.Point && geom2 != null
			&& geom2.getGeometry() != null
			&& geom2.getGeometry().getType() == Type.Point) {
		Point corePt1 = (Point) geom1.getGeometry();
		Point corePt2 = (Point) geom2.getGeometry();
		double meters = 0.0;
		try {
			meters = GeometryEngine.geodesicDistanceOnWGS84(corePt1,
					corePt2);
		} catch (Throwable error) {
			LOGGER.error(error.getMessage());
		}

		double feet = meter2feet(meters);
		if (feet >= tolerance)
			return true;
		else
			return false;
	} else {
		throw new RuntimeException(
				LOGGER.translate("INVALID_GEOMETRY_TYPE"));
	}
}
 
Example #6
Source File: BearingProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
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 #7
Source File: IncrementalPointProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private GeoEvent createIncrementalPointGeoevent(GeoEvent event, MapGeometry outGeo, Date timestart, Integer increment) throws MessagingException, FieldException
{
	long multiplier = increment+1;
	long timeFromStart = timeInterval*multiplier;
	long incrementTime = timestart.getTime() + (timeFromStart);
	double timeFromStartMinutes = timeFromStart/60000.0;
	Double distOnLine = distInterval*multiplier;
	Date ts = new Date(incrementTime);
	GeoEvent msg = geoEventCreator.create(outDef, definition.getUri().toString());
	for(FieldDefinition fd: event.getGeoEventDefinition().getFieldDefinitions())
	{
		
		if(fd.getTags().contains("GEOMETRY"))
		{
			msg.setGeometry(outGeo);
		}
		else if(fd.getTags().contains("TRACK_ID"))
		{
			String trackid = event.getTrackId() + "_" + increment.toString();
			msg.setField("TRACK_ID", trackid);
		}
		else
		{
			msg.setField(fd.getName(), event.getField(fd.getName()));
		}
	}
	msg.setField("TIMESTAMP", ts);
	msg.setField("TIME_FROM_START", timeFromStartMinutes);
	msg.setField("DISTANCE_ON_LINE", distOnLine);
	msg.setProperty(GeoEventPropertyName.TYPE, "event");
	msg.setProperty(GeoEventPropertyName.OWNER_ID, getId());
	msg.setProperty(GeoEventPropertyName.OWNER_URI,
			definition.getUri());
	return msg;
}
 
Example #8
Source File: IncrementalPointProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private GeoEvent createVertexGeoevent(GeoEvent event, MapGeometry outGeo, double dist, long time, double timeFromStartMinutes, Integer increment) throws MessagingException, FieldException
{
	Date ts = new Date(time);
	Double distOnLine = dist;
	GeoEvent msg = geoEventCreator.create(outDef, definition.getUri().toString());
	for(FieldDefinition fd: event.getGeoEventDefinition().getFieldDefinitions())
	{
		
		if(fd.getTags().contains("GEOMETRY"))
		{
			msg.setGeometry(outGeo);
		}
		else if(fd.getTags().contains("TRACK_ID"))
		{
			String trackid = event.getTrackId() + "_" + increment.toString();
			msg.setField("TRACK_ID", trackid);
		}
		else
		{
			msg.setField(fd.getName(), event.getField(fd.getName()));
		}
	}
	msg.setField("TIMESTAMP", ts);
	msg.setField("TIME_FROM_START", timeFromStartMinutes);
	msg.setField("DISTANCE_ON_LINE", distOnLine);
	msg.setProperty(GeoEventPropertyName.TYPE, "event");
	msg.setProperty(GeoEventPropertyName.OWNER_ID, getId());
	msg.setProperty(GeoEventPropertyName.OWNER_URI,
			definition.getUri());
	return msg;
}
 
Example #9
Source File: IncrementalPointProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private void processVertices(GeoEvent ge, Polyline polyln, double distTotal, long start, long end, LinearUnit lu, Boolean projected) throws MessagingException, FieldException
{
	int count = polyln.getPointCount();
	double currentDist = 0;
	long currentTime = start;
	long totalTime = end - start;
	Geometry outGeo = null;
	Point projGeo = null;
	Point lastPoint = null;
	for(int i = 0; i < count; ++i)
	{
		projGeo = polyln.getPoint(i);
		
		if(i!=0)
		{
			Polyline seg = new Polyline();
			seg.startPath(lastPoint);
			seg.lineTo(projGeo);
			double segDist = GeometryEngine.geodesicLength(seg, processSr, lu);
			currentDist += segDist;
			double percent = currentDist/distTotal;
			currentTime = (long) Math.floor((start + (totalTime*percent)));
			
		}
		if(projected)
		{
			outGeo = GeometryEngine.project(projGeo, processSr, outSr);
		}
		else
		{
			outGeo=projGeo;
		}
		MapGeometry outMapGeo = new MapGeometry(outGeo, outSr);
		double minutesFromStart = (currentTime - start)/60000;
		GeoEvent msg = createVertexGeoevent(ge, outMapGeo, currentDist, currentTime, minutesFromStart, i);
		send(msg);
		lastPoint = projGeo;
	}
}
 
Example #10
Source File: SpatialQProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private MapGeometry constructGeometryFromString(String geoString) {
	String[] pairs = geoString.split(" ");

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

		String[] tuple = coords.split(",");
		Double x = Double.parseDouble(tuple[0]);
		Double y = Double.parseDouble(tuple[1]);
		Point p = new Point(x, y);
		Double z = Double.NaN;
		if (tuple.length > 2) {
			z = Double.parseDouble(tuple[2]);
			p.setZ(z);
		}
		if (firstit) {
			polygon.startPath(p);
			firstit = false;
		} else {
			polygon.lineTo(p);
		}
	}
	polygon.closeAllPaths();
	MapGeometry mapgeo = new MapGeometry(polygon, srOut);
	return mapgeo;
}
 
Example #11
Source File: SpatialQProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
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: SpatialQProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
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 #13
Source File: TrackIdleProcessorStart.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
public TrackIdleProcessorStart(String trackId, Date startTime, MapGeometry geometry)
{
	this.trackId = trackId;
	this.startTime = startTime;
	this.geometry = geometry;
	this.setIdling(false);
	this.idleDuration = 0;
}
 
Example #14
Source File: Polygon2PtProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
@Override
public GeoEvent process(GeoEvent ge) throws Exception {
	
	MapGeometry mapGeo = ge.getGeometry();
	Geometry geo = mapGeo.getGeometry();
	if(geo.getType()!=Geometry.Type.Polygon)
		return null;
	Point center = GeometryUtility.CenterOfMass((Polygon)geo);
	MapGeometry outMapGeo = new MapGeometry(center, mapGeo.getSpatialReference());
	ge.setGeometry(outMapGeo);
	return ge;
}
 
Example #15
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
{
	MapGeometry eventgeo = ge.getGeometry();
	Geometry geo = eventgeo.getGeometry();
	Geometry maskGeo = GeometryEngine.project(geo, srIn, srBuffer);
	return GeometryEngine.geometryToJson(srBuffer, maskGeo);
}
 
Example #16
Source File: BearingProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private MapGeometry GenerateGeometry(Double ox, Double oy, Double dx, Double dy, SpatialReference sr)
{
	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 mapGeo = new MapGeometry(ln, sr);
	return mapGeo;
	
}
 
Example #17
Source File: MainActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a geojson string to com.esri.core.geometry.Point.
 *
 * @param jsonPoint geoJson string representation of a Point
 * @return com.esri.core.geometry.Point
 * @throws Exception
 */
static Point createPointFromGeoJson(String jsonPoint) throws Exception {

    MapGeometry mapGeom = OperatorImportFromGeoJson.local().execute(GeoJsonImportFlags.geoJsonImportDefaults,
            Geometry.Type.Point,
            jsonPoint,
            null);

    return (Point) mapGeom.getGeometry();
}
 
Example #18
Source File: EllipseProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
@Override
public GeoEvent process(GeoEvent ge) throws Exception {
	
	if(!ge.getGeoEventDefinition().getTagNames().contains("GEOMETRY"))
	{
		return null;
	}
	inwkid = ge.getGeometry().getSpatialReference().getID();
	if(majAxisSource.equals("Event"))
	{
		majorAxisRadius = (Double)ge.getField(majorAxisField);
	}
	if(minAxisSource.equals("Event"))
	{
		minorAxisRadius = (Double)ge.getField(minorAxisField);
	}
	if(rotSource.equals("Event"))
	{
		rotation=(Double)ge.getField(rotationField);
	}
	
	MapGeometry mapGeo = ge.getGeometry();
	Geometry geo = mapGeo.getGeometry();
	if(!(geo instanceof Point))
	{
		return null;
	}
	Point eventGeo = (Point)geo;
	double x = eventGeo.getX();
	double y = eventGeo.getY();
	double rdeg = GeometryUtility.Geo2Arithmetic(rotation);
	double r = Math.toRadians(rdeg);
	MapGeometry ellipse = constructEllipse(x, y, majorAxisRadius, minorAxisRadius, r, inwkid, procwkid, outwkid);
	ge.setGeometry(ellipse);
	return ge;
}
 
Example #19
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
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;
	//String json = GeometryEngine.geometryToJson(srOut, bufferout);
	//return spatial.fromJson(json);
	
}
 
Example #20
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private MapGeometry constructGeometryFromString(String geoString)
{
	String[] pairs = geoString.split(" ");
	
	Polygon polygon = new Polygon();
	Boolean firstit = true;
	for(String coords: pairs)
	{
		
		String[] tuple = coords.split(",");
		Double x = Double.parseDouble(tuple[0]);
		Double y = Double.parseDouble(tuple[1]);
		Point p = new Point(x,y);
		Double z = Double.NaN;
		if (tuple.length>2)
		{
			z = Double.parseDouble(tuple[2]);
			p.setZ(z);
		}
		if(firstit)
		{
			polygon.startPath(p);
			firstit=false;
		}
		else
		{
			polygon.lineTo(p);
		}
	}
	polygon.closeAllPaths();
	MapGeometry mapgeo = new MapGeometry(polygon, srOut);
	return mapgeo;
}
 
Example #21
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
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 #22
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 #23
Source File: OGCGeometry.java    From geometry-api-java with Apache License 2.0 4 votes vote down vote up
public static OGCGeometry fromJson(String string) {
	MapGeometry mapGeom = GeometryEngine.jsonToGeometry(JsonParserReader.createFromString(string));
	return OGCGeometry.createFromEsriGeometry(mapGeom.getGeometry(),
			mapGeom.getSpatialReference());
}
 
Example #24
Source File: GeoFunctions.java    From calcite with Apache License 2.0 4 votes vote down vote up
MapGeom(MapGeometry mg) {
  this.mg = Objects.requireNonNull(mg);
}
 
Example #25
Source File: GeoFunctions.java    From calcite with Apache License 2.0 4 votes vote down vote up
private static MapGeom bind(Geometry geometry, SpatialReference sr) {
  return new MapGeom(new MapGeometry(geometry, sr));
}
 
Example #26
Source File: EsriJsonSerDe.java    From spatial-framework-for-hadoop with Apache License 2.0 4 votes vote down vote up
@Override
protected OGCGeometry parseGeom(JsonParser parser) {
	MapGeometry mapGeom = GeometryEngine.jsonToGeometry(parser);
	return OGCGeometry.createFromEsriGeometry(mapGeom.getGeometry(), mapGeom.getSpatialReference());
}
 
Example #27
Source File: JsonSerDeTestingBase.java    From spatial-framework-for-hadoop with Apache License 2.0 4 votes vote down vote up
protected void addWritable(ArrayList<Object> stuff, MapGeometry geom) {
	addWritable(stuff, geom.getGeometry(), geom.getSpatialReference());
}
 
Example #28
Source File: GeoFunctions.java    From Bats with Apache License 2.0 4 votes vote down vote up
private static MapGeom bind(Geometry geometry, SpatialReference sr) {
  return new MapGeom(new MapGeometry(geometry, sr));
}
 
Example #29
Source File: CoTAdapter.java    From defense-solutions-proofs-of-concept with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("incomplete-switch")
private void traverseBranch(Node node, FieldGroup fieldGroup, FieldDefinition fieldDefinition) throws FieldException
{
	if( node == null ) return;
	//System.out.println("Examining node named \""+node.getNodeName()+"\"");
	FieldType fieldType = fieldDefinition.getType();
	switch( fieldType )
	{
	case Group:
		FieldGroup childFieldGroup = fieldGroup.createFieldGroup(fieldDefinition.getName());
		fieldGroup.setField( fieldDefinition.getName(), childFieldGroup);
		for( FieldDefinition childFieldDefinition : fieldDefinition.getChildren() )
		{
			String childName = childFieldDefinition.getName();
			List<Node> childNodes = findChildNodes( node, childName );
			if( childNodes.size() > 0 )
			{
				for( Node childNode : childNodes )
					traverseBranch( childNode, childFieldGroup, childFieldDefinition );
			}
			else
				traverseBranch( node, childFieldGroup, childFieldDefinition );
		}
		break;
	case String:
		String value = getAttribute( node, fieldDefinition.getName() );
		if( value != null )
			fieldGroup.setField(fieldDefinition.getName(), value);
		break;
	case Integer:
		value = getAttribute( node, fieldDefinition.getName() );
		if( value != null )
			fieldGroup.setField(fieldDefinition.getName(), new Integer(value));
		break;
	case Double:
		value = getAttribute( node, fieldDefinition.getName() );
		if( value != null )
			fieldGroup.setField(fieldDefinition.getName(), new Double(value));
		break;
	case Boolean:
		value = getAttribute( node, fieldDefinition.getName() );
		if( value != null )
			fieldGroup.setField(fieldDefinition.getName(), new Boolean(value));
		break;
	case Date:
		value = getAttribute( node, fieldDefinition.getName() );
		if( value != null )
		{
			Date date = new Date();
			try
			{
				date = parseCoTDate(value);
			}catch(Exception ex)
			{
			}
			fieldGroup.setField(fieldDefinition.getName(), date);
		}
		break;
	case Geometry:
		MapGeometry geometry = createGeometry(node);
		if( geometry != null )
			fieldGroup.setField(fieldDefinition.getName(), geometry);
		break;
	case Long:
		value = getAttribute( node, fieldDefinition.getName() );
		if( value != null )
			fieldGroup.setField(fieldDefinition.getName(), new Long(value));
		break;
	case Short:
		value = getAttribute( node, fieldDefinition.getName() );
		if( value != null )
			fieldGroup.setField(fieldDefinition.getName(), new Integer(value));
		break;
	}
}
 
Example #30
Source File: TrackIdleProcessorStart.java    From defense-solutions-proofs-of-concept with Apache License 2.0 4 votes vote down vote up
public void setGeometry(MapGeometry geometry)
{
	this.geometry = geometry;
}