com.vividsolutions.jts.geom.Point Java Examples

The following examples show how to use com.vividsolutions.jts.geom.Point. 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: GeoServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Geometry createCircle(final Point point, final double radius, final int nrPoints) {
	double x = point.getX();
	double y = point.getY();
	Coordinate[] coords = new Coordinate[nrPoints + 1];
	for (int i = 0; i < nrPoints; i++) {
		double angle = ((double) i / (double) nrPoints) * Math.PI * 2.0;
		double dx = Math.cos(angle) * radius;
		double dy = Math.sin(angle) * radius;
		coords[i] = new Coordinate(x + dx, y + dy);
	}
	coords[nrPoints] = coords[0];

	LinearRing ring = point.getFactory().createLinearRing(coords);
	return point.getFactory().createPolygon(ring, null);
}
 
Example #2
Source File: FacetSequenceTreeBuilder.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates facet sequences
 * 
 * @param g
 * @return List<GeometryFacetSequence>
 */
private static List computeFacetSequences(Geometry g) {
  final List sections = new ArrayList();

  g.apply(new GeometryComponentFilter() {

    public void filter(Geometry geom) {
      CoordinateSequence seq = null;
      if (geom instanceof LineString) {
        seq = ((LineString) geom).getCoordinateSequence();
        addFacetSequences(seq, sections);
      }
      else if (geom instanceof Point) {
        seq = ((Point) geom).getCoordinateSequence();
        addFacetSequences(seq, sections);
      }
    }
  });
  return sections;
}
 
Example #3
Source File: GamaKmlExport.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Add a placemark with a geometry object.The geometry can be a Point, a Line, a Polygon or any Multi-geometry.
 * Points will be represented by an icon and linear or surface objects will be drawn.
 *
 * @param label
 *            The title of the folder that will be created for this ShpRecord
 * @param beginDate
 *            Begining date of the timespan
 * @param endDate
 *            End date of the timespan
 * @param geom
 *            Geometry object to be drawn
 * @param height
 *            Height of the feature to draw. If > 0 the feature will be shown extruded to the given height
 *            (relative to the ground level). If <= 0 the feature will be drawn flat on the ground.
 */
public void addGeometry(final IScope scope, final String label, final String beginDate, final String endDate,
		final IShape shape, final String styleName, final double height) {
	final Placemark placemark = fold.createAndAddPlacemark().withStyleUrl("#" + styleName);
	placemark.setName(label);
	placemark.createAndSetTimeSpan().withBegin(beginDate).withEnd(endDate);

	final IShape shapeTM = Spatial.Projections.transform_CRS(scope, shape, "EPSG:4326");
	final Geometry geom = shapeTM.getInnerGeometry();

	if (geom instanceof Point) {
		addPoint(placemark, (Point) geom, height);
	} else if (geom instanceof LineString) {
		addLine(placemark, (LineString) geom, height);
	} else if (geom instanceof Polygon) {
		addPolygon(placemark, (Polygon) geom, height);
	} else if (geom instanceof MultiPoint) {
		addMultiPoint(placemark, (MultiPoint) geom, height);
	} else if (geom instanceof MultiLineString) {
		addMultiLine(placemark, (MultiLineString) geom, height);
	} else if (geom instanceof MultiPolygon) {
		addMultiPolygon(placemark, (MultiPolygon) geom, height);
	}
}
 
Example #4
Source File: WKBWriter.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Writes a {@link Geometry} to an {@link OutStream}.
 *
 * @param geom the geometry to write
 * @param os the out stream to write to
 * @throws IOException if an I/O error occurs
 */
public void write(Geometry geom, OutStream os) throws IOException
{
  if (geom instanceof Point)
    writePoint((Point) geom, os);
  // LinearRings will be written as LineStrings
  else if (geom instanceof LineString)
    writeLineString((LineString) geom, os);
  else if (geom instanceof Polygon)
    writePolygon((Polygon) geom, os);
  else if (geom instanceof MultiPoint)
    writeGeometryCollection(WKBConstants.wkbMultiPoint, 
        (MultiPoint) geom, os);
  else if (geom instanceof MultiLineString)
    writeGeometryCollection(WKBConstants.wkbMultiLineString,
        (MultiLineString) geom, os);
  else if (geom instanceof MultiPolygon)
    writeGeometryCollection(WKBConstants.wkbMultiPolygon,
        (MultiPolygon) geom, os);
  else if (geom instanceof GeometryCollection)
    writeGeometryCollection(WKBConstants.wkbGeometryCollection,
        (GeometryCollection) geom, os);
  else {
    Assert.shouldNeverReachHere("Unknown Geometry type");
  }
}
 
Example #5
Source File: MiscellaneousTest.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testPredicatesReturnFalseForEmptyGeometries() {
  Point p1 = new GeometryFactory().createPoint((Coordinate)null);
  Point p2 = new GeometryFactory().createPoint(new Coordinate(5,5));
  assertEquals(false, p1.equals(p2));
  assertEquals(true, p1.disjoint(p2));
  assertEquals(false, p1.intersects(p2));
  assertEquals(false, p1.touches(p2));
  assertEquals(false, p1.crosses(p2));
  assertEquals(false, p1.within(p2));
  assertEquals(false, p1.contains(p2));
  assertEquals(false, p1.overlaps(p2));

  assertEquals(false, p2.equals(p1));
  assertEquals(true, p2.disjoint(p1));
  assertEquals(false, p2.intersects(p1));
  assertEquals(false, p2.touches(p1));
  assertEquals(false, p2.crosses(p1));
  assertEquals(false, p2.within(p1));
  assertEquals(false, p2.contains(p1));
  assertEquals(false, p2.overlaps(p1));
}
 
Example #6
Source File: SameStructureTester.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static boolean isSameStructure(Geometry g1, Geometry g2)
{
  if (g1.getClass() != g2.getClass())
    return false;
  if (g1 instanceof GeometryCollection)
    return isSameStructureCollection((GeometryCollection) g1, (GeometryCollection) g2);
  else if (g1 instanceof Polygon)
    return isSameStructurePolygon((Polygon) g1, (Polygon) g2);
  else if (g1 instanceof LineString)
    return isSameStructureLineString((LineString) g1, (LineString) g2);
  else if (g1 instanceof Point)
    return isSameStructurePoint((Point) g1, (Point) g2);

  Assert.shouldNeverReachHere(
      "Unsupported Geometry class: " + g1.getClass().getName());
  return false;
}
 
Example #7
Source File: AllowedAttributeTypes.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initialise.
 */
private static void initialise()
{
    List<Class<?> > doubleList = new ArrayList<Class<?> >(Arrays.asList(Integer.class, Long.class, Double.class, Float.class));
    List<Class<?> > integerList = new ArrayList<Class<?> >(Arrays.asList(Integer.class, Long.class));
    List<Class<?> > stringList = new ArrayList<Class<?> >(Arrays.asList(String.class));
    List<Class<?> > geometryList = new ArrayList<Class<?> >(Arrays.asList(Point.class, LineString.class, Polygon.class, MultiPolygon.class, MultiPoint.class, MultiLineString.class));

    allowedClassTypeMap.put(String.class, stringList);
    allowedClassTypeMap.put(Double.class, doubleList);
    allowedClassTypeMap.put(Float.class, doubleList);
    allowedClassTypeMap.put(Integer.class, integerList);
    allowedClassTypeMap.put(Long.class, integerList);
    allowedClassTypeMap.put(Geometry.class, geometryList);

    List<Class<?> > objectList = new ArrayList<Class<?>>();
    objectList.addAll(doubleList);
    objectList.addAll(integerList);
    objectList.addAll(stringList);
    objectList.addAll(geometryList);
    allowedClassTypeMap.put(Object.class, objectList);
}
 
Example #8
Source File: KMLWriter.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writeGeometry(Geometry g, int level, StringBuffer buf) {
  String attributes = "";
  if (g instanceof Point) {
    writePoint((Point) g, attributes, level, buf);
  } else if (g instanceof LinearRing) {
    writeLinearRing((LinearRing) g, attributes, true, level, buf);
  } else if (g instanceof LineString) {
    writeLineString((LineString) g, attributes, level, buf);
  } else if (g instanceof Polygon) {
    writePolygon((Polygon) g, attributes, level, buf);
  } else if (g instanceof GeometryCollection) {
    writeGeometryCollection((GeometryCollection) g, attributes, level, buf);
  }
  else 
    throw new IllegalArgumentException("Geometry type not supported: " + g.getGeometryType());
}
 
Example #9
Source File: ShpConnector.java    From TripleGeo with GNU General Public License v3.0 6 votes vote down vote up
/**
  * 
  * Point geometry according to WGS84 Geoposition RDF vocabulary
  */
 private void insertWGS84Point(String resource, Geometry geo) 
 {
Point p = (Point) geo;
   insertLiteralTriplet(
       configuration.nsUri + resource,
       Constants.NSPOS + Constants.LONGITUDE,
       String.valueOf(p.getX()),     //X-ordinate as a property
       Constants.NSXSD + "decimal"
       );
   
   insertLiteralTriplet(
           configuration.nsUri + resource,
           Constants.NSPOS + Constants.LATITUDE,
           String.valueOf(p.getY()),   //Y-ordinate as a property
           Constants.NSXSD + "decimal"
           );

 }
 
Example #10
Source File: Distance3DOp.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void computeMinDistanceOneMulti(PlanarPolygon3D poly, Geometry geom, boolean flip) {
	if (geom instanceof GeometryCollection) {
		int n = geom.getNumGeometries();
		for (int i = 0; i < n; i++) {
			Geometry g = geom.getGeometryN(i);
			computeMinDistanceOneMulti(poly, g, flip);
			if (isDone)	return;
		}
	}
	else {
		if (geom instanceof Point) {
			computeMinDistancePolygonPoint(poly, (Point) geom, flip);
			return;
		}
		if (geom instanceof LineString) {
			computeMinDistancePolygonLine(poly, (LineString) geom, flip);
			return;
		}
		if (geom instanceof Polygon) {
			computeMinDistancePolygonPolygon(poly, (Polygon) geom, flip);
			return;
		}
	}
}
 
Example #11
Source File: InternalFeatureCollection.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
private Class getGeometryBinding(LayerType layerType) {
	switch (layerType) {
		case LINESTRING:
			return Geometry.class;
		case MULTILINESTRING:
			return MultiLineString.class;
		case MULTIPOINT:
			return MultiPoint.class;
		case MULTIPOLYGON:
			return MultiPolygon.class;
		case POINT:
			return Point.class;
		case POLYGON:
			return Polygon.class;
		default:
			return Geometry.class;
	}
}
 
Example #12
Source File: GeoIndexerSfTest.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Rough conversion from geometry to GML using a template.
 * @param geo base Geometry gets delegated
 * @return String gml encoding of the gemoetry
 */
private static String geoToGmlRough(final Geometry geo) {
    final Geometries theType = org.geotools.geometry.jts.Geometries.get(geo);
    switch (theType) {
    case POINT:
        return geoToGml((Point)geo);
    case LINESTRING:
        return geoToGml((LineString)geo);
    case POLYGON:
        return geoToGml((Polygon)geo);
    case MULTIPOINT:
    case MULTILINESTRING:
    case MULTIPOLYGON:
    default:
        throw new Error("No code to convert to GML for this type: "+theType);
    }
}
 
Example #13
Source File: DtoConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Convert a layer type to a geometry class.
 * 
 * @param layerType
 *            layer type
 * @return JTS class
 */
public Class<? extends com.vividsolutions.jts.geom.Geometry> toInternal(LayerType layerType) {
	switch (layerType) {
		case GEOMETRY:
			return com.vividsolutions.jts.geom.Geometry.class;
		case LINESTRING:
			return LineString.class;
		case MULTILINESTRING:
			return MultiLineString.class;
		case POINT:
			return Point.class;
		case MULTIPOINT:
			return MultiPoint.class;
		case POLYGON:
			return Polygon.class;
		case MULTIPOLYGON:
			return MultiPolygon.class;
		case RASTER:
			return null;
		default:
			throw new IllegalStateException("Don't know how to handle layer type " + layerType);
	}
}
 
Example #14
Source File: DtoConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Convert a geometry class to a layer type.
 * 
 * @param geometryClass
 *            JTS geometry class
 * @return Geomajas layer type
 */
public LayerType toDto(Class<? extends com.vividsolutions.jts.geom.Geometry> geometryClass) {
	if (geometryClass == LineString.class) {
		return LayerType.LINESTRING;
	} else if (geometryClass == MultiLineString.class) {
		return LayerType.MULTILINESTRING;
	} else if (geometryClass == Point.class) {
		return LayerType.POINT;
	} else if (geometryClass == MultiPoint.class) {
		return LayerType.MULTIPOINT;
	} else if (geometryClass == Polygon.class) {
		return LayerType.POLYGON;
	} else if (geometryClass == MultiPolygon.class) {
		return LayerType.MULTIPOLYGON;
	} else {
		return LayerType.GEOMETRY;
	}
}
 
Example #15
Source File: JTSHelper.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
/**
 * Create GeoJSON Point coordinates.
 */
public static PointCoordinates createPointCoordinates(Point geom) {
  if (geom == null) {
    return null;
  }
  final Coordinate coordinate = geom.getCoordinate();

  return (Double.isNaN(coordinate.z))
      ? new PointCoordinates(coordinate.x, coordinate.y) : new PointCoordinates(coordinate.x, coordinate.y, coordinate.z);
}
 
Example #16
Source File: DescribeSensorParserTest.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
@Test 
public void shouldParseStrict4326PositionToCrs84Position() throws XmlException, IOException, FactoryException, TransformException {
    XmlObject sml = loadXmlFileViaClassloader(SML_POSITION_VECTOR_4326, getClass());
    DescribeSensorParser parser = createParserFromFile(sml, getSimpleMetadata());
    
    /*
     * We expect a lon/lat ordered coordinate as the inner CRS is CRS:84
     */
    Point actual = parser.buildUpSensorMetadataPosition();
    assertThat("X value (latitude) is incorrect.", actual.getX(), is(crs84Point.getX()));
    assertThat("Y value (longitude) is incorrect.", actual.getY(), is(crs84Point.getY()));
}
 
Example #17
Source File: DescribeSensorParserTest.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void shouldParseXYOdered31466FromPositionTypeWithNamedLatitudeLongitudeAxes() throws FactoryException, TransformException, XmlException, IOException, XMLHandlingException {
    MyDescribeSensorParser parser = new MyDescribeSensorParser(getSimpleMetadata());
    Point actual = parser.testPointCreation(createStrictEpsg31466());
    assertThat("X value (latitude) is incorrect.", actual.getX(), closeTo(crs84TransformationResult.getX(), ALLOWED_DELTA));
    assertThat("Y value (longitude) is incorrect.", actual.getY(), closeTo(crs84TransformationResult.getY(), ALLOWED_DELTA));
    
    actual = parser.testPointCreation(createStrictEpsg31466ShortNames());
    assertThat("X value (latitude) is incorrect.", actual.getX(), closeTo(crs84TransformationResult.getX(), ALLOWED_DELTA));
    assertThat("Y value (longitude) is incorrect.", actual.getY(), closeTo(crs84TransformationResult.getY(), ALLOWED_DELTA));
}
 
Example #18
Source File: AbstractTopology.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public Geometry returnToroidalGeom(final GamaPoint loc) {
	final List<Geometry> geoms = new ArrayList<>();
	final Point pt = GeometryUtils.GEOMETRY_FACTORY.createPoint(loc);
	final AffineTransformation at = new AffineTransformation();
	geoms.add(pt);
	for (int cnt = 0; cnt < 8; cnt++) {
		at.setToTranslation(getAdjustedXYVector()[cnt][0], getAdjustedXYVector()[cnt][1]);
		geoms.add(at.transform(pt));
	}
	return GeometryUtils.GEOMETRY_FACTORY.buildGeometry(geoms);
}
 
Example #19
Source File: ShapeInMemFeatureModelTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void setGeometry() throws Exception {
	WKTReader wktReader = new WKTReader();
	Point pt = (Point) wktReader.read("POINT (5 5)");
	featureModel.setGeometry(feature, pt);
	Assert.assertEquals(5, featureModel.getGeometry(feature).getCoordinate().x, 0.00001);
}
 
Example #20
Source File: DataSourcePointOverlay.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTap(GeoPoint geoPoint, MapView mapView) {
    if(overlayItemTapListener == null)
        return false;
    
    Projection projection = mapView.getProjection();
    android.graphics.Point eventPosition = projection.toPixels(geoPoint,
            null);

    if (eventPosition == null)
        return false;

    android.graphics.Point checkItemPoint = new android.graphics.Point();

    for (Integer index : visiblePointOverlays) {
        PointOverlayType pointOverlay = pointOverlays.get(index);
        if (pointOverlay.getPoint() == null)
            continue;

        checkItemPoint = projection.toPixels(pointOverlay.getPoint(),
                checkItemPoint);

        Rect markerBounds = pointOverlay.marker.getBounds();
        int checkLeft = checkItemPoint.x + markerBounds.left;
        int checkRight = checkItemPoint.x + markerBounds.right;
        int checkTop = checkItemPoint.y + markerBounds.top;
        int checkBottom = checkItemPoint.y + markerBounds.bottom;

        if (checkRight >= eventPosition.x //
                && checkLeft <= eventPosition.x
                && checkBottom >= eventPosition.y
                && checkTop <= eventPosition.y) {
            overlayItemTapListener.onOverlayItemTap(pointOverlays.get(index));
            return true;
        }
    }

    return false;
}
 
Example #21
Source File: PointGenerator.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @see com.vividsolutions.jts.generator.GeometryGenerator#create()
 * @throws NullPointerException when either the Geometry Factory, or the Bounding Box are undefined.
 */
public Geometry create() {
	if(geometryFactory == null){
		throw new NullPointerException("GeometryFactory is not declared");
	}
	if(boundingBox == null || boundingBox.isNull()){
		throw new NullPointerException("Bounding Box is not declared");
	}
	
	Point p = geometryFactory.toGeometry(boundingBox).getCentroid();
	geometryFactory.getPrecisionModel().makePrecise(p.getCoordinate());
	return p;
}
 
Example #22
Source File: PointImpl.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Override
public void fromJTS(Point jtsPoint)
{
  x = jtsPoint.getX();
  y = jtsPoint.getY();

  hash = false;
}
 
Example #23
Source File: GeoUtil.java    From fiware-cepheus with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Transform a Geometry to NGSI location coordinates (two comma separated double numbers using point as decimal separator).
 * First number is latitude, second is longitude. Ex: "49.2323, 1.334".
 * @param geometry
 * @return
 */
public static String toNGSIString(Geometry geometry) throws IllegalArgumentException {
    if (geometry instanceof Point) {
        Coordinate coordinate = geometry.getCoordinate();
        return coordinate.getOrdinate(Coordinate.Y) + ", " + coordinate.getOrdinate(Coordinate.X);
    }
    throw new IllegalArgumentException("cannot output geometry, only Point is supported");
}
 
Example #24
Source File: FeatureParserTest.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
@Test public void
shouldParseLocations() throws XmlException, IOException {
    XmlObject featureResponse = loadXmlFileViaClassloader(GET_FOI_RESPONSE, getClass());
    Map<Feature, Point> featureLocations = featureParser.parseFeatures(featureResponse.newInputStream());
    if (featureLocations == null || featureLocations.isEmpty()) {
        fail("No features have been parsed!");
    } else {
        assertThat(featureLocations.size(), is(3));
    }
}
 
Example #25
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Geometry toGeometry(GeometryFactory factory, AbstractGeometryInfo geom) throws LayerException {
	Geometry geometry = null;
	if (geom instanceof AbstractGeometryCollectionInfo) {
		AbstractGeometryCollectionInfo geomCollection = (AbstractGeometryCollectionInfo) geom;
		List<GeometryMemberInfo> members = geomCollection.getGeometryMemberList();
		if (geom instanceof MultiPointInfo) {
			Point[] points = new Point[members.size()];
			for (int i = 0; i < members.size(); i++) {
				points[i] = (Point) toSimpleGeometry(factory, members.get(i).getGeometry());
			}
			geometry = factory.createMultiPoint(points);
		} else if (geom instanceof MultiLineStringInfo) {
			LineString[] lines = new LineString[members.size()];
			for (int i = 0; i < members.size(); i++) {
				lines[i] = (LineString) toSimpleGeometry(factory, members.get(i).getGeometry());
			}
			geometry = factory.createMultiLineString(lines);
		} else if (geom instanceof MultiPolygonInfo) {
			Polygon[] polygons = new Polygon[members.size()];
			for (int i = 0; i < members.size(); i++) {
				polygons[i] = (Polygon) toSimpleGeometry(factory, members.get(i).getGeometry());
			}
			geometry = factory.createMultiPolygon(polygons);
		} else if (geom instanceof MultiGeometryInfo) {
			Geometry[] geometries = new Geometry[members.size()];
			for (int i = 0; i < members.size(); i++) {
				geometries[i] = toGeometry(factory, members.get(i).getGeometry());
			}
			geometry = factory.createGeometryCollection(geometries);
		}
	} else {
		geometry = toSimpleGeometry(factory, geom);
	}
	return geometry;
}
 
Example #26
Source File: GeoWaveIndexerSfTest.java    From rya with Apache License 2.0 5 votes vote down vote up
private static String geoToGml(final Point point) {
    //CRS:84 long X,lat Y
    //ESPG:4326 lat Y,long X
    return "<Point"//
    + " srsName='CRS:84'"// TODO: point.getSRID()
    + "><pos>"+point.getX()+" "+point.getY()+"</pos>  "// assumes  Y=lat  X=long
    + " </Point>";
}
 
Example #27
Source File: GeoIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestrictPredicatesSearch() throws Exception {
    conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2");
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(conf);

        final ValueFactory vf = SimpleValueFactory.getInstance();

        final Point point = gf.createPoint(new Coordinate(10, 10));
        final Value pointValue = vf.createLiteral("Point(10 10)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final IRI invalidPredicate = GeoConstants.GEO_AS_WKT;

        // These should not be stored because they are not in the predicate list
        f.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj1"), invalidPredicate, pointValue)));
        f.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj2"), invalidPredicate, pointValue)));

        final IRI pred1 = vf.createIRI("pred:1");
        final IRI pred2 = vf.createIRI("pred:2");

        // These should be stored because they are in the predicate list
        final Statement s3 = vf.createStatement(vf.createIRI("foo:subj3"), pred1, pointValue);
        final Statement s4 = vf.createStatement(vf.createIRI("foo:subj4"), pred2, pointValue);
        f.storeStatement(convertStatement(s3));
        f.storeStatement(convertStatement(s4));

        // This should not be stored because the object is not valid wkt
        f.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj5"), pred1, vf.createLiteral("soint(10 10)"))));

        // This should not be stored because the object is not a literal
        f.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj6"), pred1, vf.createIRI("p:Point(10 10)"))));

        f.flush();

        final Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS));
        Assert.assertEquals(2, actual.size());
        Assert.assertTrue(actual.contains(s3));
        Assert.assertTrue(actual.contains(s4));
    }
}
 
Example #28
Source File: SimpleFeatureModelTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void setGeometry() throws LayerException {
	Point point = geometryFactory.createPoint(new Coordinate(1, 2));
	featureModel.setGeometry(feature1, point);

	Geometry geometry = featureModel.getGeometry(feature1);
	Assert.assertNotNull(geometry);
	Assert.assertTrue(geometry instanceof Point);
	Assert.assertEquals(1.0, geometry.getCoordinate().x, 0.00001);
	Assert.assertEquals(2.0, geometry.getCoordinate().y, 0.00001);

	featureModel.setGeometry(feature1, null);
	geometry = featureModel.getGeometry(feature1);
	Assert.assertNull(geometry);
}
 
Example #29
Source File: GeoFencingAPI.java    From google-geoEngine with Apache License 2.0 5 votes vote down vote up
/**
 * Endpoint for finding the fences a certain point is in.
 */@ApiMethod(name = "point", httpMethod = "get", path = "point")
public ArrayList < MyFence > queryPoint(@Named("group") String group, @Named("lng") double lng, @Named("lat") double lat) {
    ArrayList < MyFence > fences = new ArrayList < MyFence > ();

    //Get the Index from Memcache.
    MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    GeometryFactory gf = new GeometryFactory();
    STRtree index = (STRtree) syncCache.get(group); // read from cache
    if (index != null) {
        Coordinate coord = new Coordinate(lng, lat);
        Point point = gf.createPoint(coord);
        List < MyPolygon > items = index.query(point.getEnvelopeInternal());
        if (!items.isEmpty()) {
            for (MyPolygon poly: items) {
                if (poly.contains(point)) {
                    long id = poly.getID();
                    MyFence newFence = new MyFence();
                    newFence.setId(id);
                    fences.add(newFence);
                }
            }
        }
    } else {
        try {
            MyIndex.buildIndex(group);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return fences;
}
 
Example #30
Source File: SpatialDemo.java    From HibernateDemos with The Unlicense 5 votes vote down vote up
public void addProject(String name, String locationWkt) throws Exception {
	final Project project = new Project();
	project.setName( name );
	
	project.setLocation( (Point) wktToGeometry( locationWkt ));
	
	final Session s = openSession();
	s.getTransaction().begin();
	s.persist( project );
	s.getTransaction().commit();
	s.close();
}