Java Code Examples for org.locationtech.jts.geom.GeometryFactory#createPoint()

The following examples show how to use org.locationtech.jts.geom.GeometryFactory#createPoint() . 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: GeoWaveGeometryPrecisionIT.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrecision0() {
  final GeometryFactory factory = GeometryUtils.GEOMETRY_FACTORY;
  final Geometry[] geometries =
      new Geometry[] {
          factory.createPoint(new Coordinate(12.123456789, -10.987654321)),
          factory.createLineString(
              new Coordinate[] {
                  new Coordinate(123456789.987654321, -123456789.987654321),
                  new Coordinate(987654321.123456789, -987654321.123456789)}),
          factory.createPoint(new Coordinate(0, 0))};
  final Geometry[] expected =
      new Geometry[] {
          factory.createPoint(new Coordinate(12, -11)),
          factory.createLineString(
              new Coordinate[] {
                  new Coordinate(123456790, -123456790),
                  new Coordinate(987654321, -987654321)}),
          factory.createPoint(new Coordinate(0, 0))};
  testPrecision(geometries, expected, 0);
}
 
Example 2
Source File: GeoWaveGeometryPrecisionIT.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testNegativePrecision() {
  final GeometryFactory factory = GeometryUtils.GEOMETRY_FACTORY;
  final Geometry[] geometries =
      new Geometry[] {
          factory.createPoint(new Coordinate(12.123456789, -10.987654321)),
          factory.createLineString(
              new Coordinate[] {
                  new Coordinate(123456789.987654321, -123456789.987654321),
                  new Coordinate(987654321.123456789, -987654321.123456789)}),
          factory.createPoint(new Coordinate(0, 0))};
  final Geometry[] expected =
      new Geometry[] {
          factory.createPoint(new Coordinate(0, 0)),
          factory.createLineString(
              new Coordinate[] {
                  new Coordinate(123457000, -123457000),
                  new Coordinate(987654000, -987654000)}),
          factory.createPoint(new Coordinate(0, 0))};
  testPrecision(geometries, expected, -3);
}
 
Example 3
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDWithinFilter() throws Exception {
    init();
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2));
    DWithin f = ff.dwithin(ff.property("geo"), ff.literal(ls), 3, "m");
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(2, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.01");
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.10");
}
 
Example 4
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDisjointFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2));
    Disjoint f = ff.disjoint(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(2, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.13");
}
 
Example 5
Source File: GeoWaveGeometryPrecisionIT.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrecision3() {
  final GeometryFactory factory = GeometryUtils.GEOMETRY_FACTORY;
  final Geometry[] geometries =
      new Geometry[] {
          factory.createPoint(new Coordinate(12.123456789, -10.987654321)),
          factory.createLineString(
              new Coordinate[] {
                  new Coordinate(123456789.987654321, -123456789.987654321),
                  new Coordinate(987654321.123456789, -987654321.123456789)}),
          factory.createPoint(new Coordinate(0, 0))};
  final Geometry[] expected =
      new Geometry[] {
          factory.createPoint(new Coordinate(12.123, -10.988)),
          factory.createLineString(
              new Coordinate[] {
                  new Coordinate(123456789.988, -123456789.988),
                  new Coordinate(987654321.123, -987654321.123)}),
          factory.createPoint(new Coordinate(0, 0))};
  testPrecision(geometries, expected, 3);
}
 
Example 6
Source File: JTSTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link JTS#getCoordinateReferenceSystem(Geometry)}.
 *
 * @throws FactoryException if an EPSG code can not be resolved.
 */
@Test
public void testGetCoordinateReferenceSystem() throws FactoryException {
    final GeometryFactory factory = new GeometryFactory();
    final Geometry geometry = factory.createPoint(new Coordinate(5, 6));

    CoordinateReferenceSystem crs = JTS.getCoordinateReferenceSystem(geometry);
    assertNull(crs);
    /*
     * Test CRS as user data.
     */
    geometry.setUserData(CommonCRS.ED50.geographic());
    assertEquals(CommonCRS.ED50.geographic(), JTS.getCoordinateReferenceSystem(geometry));
    /*
     * Test CRS as map value.
     */
    geometry.setUserData(Collections.singletonMap(JTS.CRS_KEY, CommonCRS.NAD83.geographic()));
    assertEquals(CommonCRS.NAD83.geographic(), JTS.getCoordinateReferenceSystem(geometry));
    /*
     * Test CRS as srid.
     */
    geometry.setUserData(null);
    geometry.setSRID(4326);
    assertEquals(CommonCRS.WGS84.geographic(), JTS.getCoordinateReferenceSystem(geometry));
}
 
Example 7
Source File: GeophilePointWithinDistanceQueryPlan.java    From fdb-record-layer with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
protected SpatialJoin.Filter<RecordWithSpatialObject, GeophileRecordImpl> getFilter(@Nonnull EvaluationContext context) {
    if (covering) {
        Double distanceValue = distance.getValue(context);
        Double centerLatitudeValue = centerLatitude.getValue(context);
        Double centerLongitudeValue = centerLongitude.getValue(context);
        if (distanceValue == null || centerLatitudeValue == null || centerLongitudeValue == null) {
            return null;
        }
        final GeometryFactory geometryFactory = new GeometryFactory();
        final Geometry center = geometryFactory.createPoint(new Coordinate(centerLatitudeValue, centerLongitudeValue));
        return (spatialObject, record) -> {
            Point point = (Point)record.spatialObject();
            Geometry geometry = geometryFactory.createPoint(new Coordinate(point.x(), point.y()));
            return geometry.isWithinDistance(center, distanceValue);
        };
    } else {
        return null;
    }
}
 
Example 8
Source File: JTSHelperTest.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Test
public void factoryFromSridShouldSetSrid() {
    GeometryFactory factory = getGeometryFactoryForSRID(4326);
    assertThat(factory, is(notNullValue()));
    Geometry g = factory.createPoint(new Coordinate(1, 2));
    assertThat(g, is(notNullValue()));
    assertThat(g.getSRID(), is(4326));
}
 
Example 9
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTouchesFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Point ls = gf.createPoint(sf.create(new double[] { 1, 1 }, 2));
    Touches f = ff.touches(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");
}
 
Example 10
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBeyondFilter() throws Exception {
    init();
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2));
    Beyond f = ff.beyond(ff.property("geo"), ff.literal(ls), 1, "m");
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(9, features.size());
}
 
Example 11
Source File: ArrayUtil.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Computes the smallest convex <code>Polygon</code> that contains all the
 * points
 *
 * @param x X array
 * @param y Y array
 * @return PolygonShape
 */
public static PolygonShape convexHull(Array x, Array y) {
    int n = (int) x.getSize();
    Geometry[] geos = new Geometry[n];
    GeometryFactory factory = new GeometryFactory();
    for (int i = 0; i < n; i++) {
        Coordinate c = new Coordinate(x.getDouble(i), y.getDouble(i));
        geos[i] = factory.createPoint(c);
    }
    Geometry gs = factory.createGeometryCollection(geos);
    Geometry ch = gs.convexHull();
    return new PolygonShape(ch);
}
 
Example 12
Source File: FastLiteShape.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public FastLiteShape( Geometry geom ) {
    super(geom, new AffineTransform(), false);
    this.prepared = PreparedGeometryFactory.prepare(geom);
    GeometryFactory gf = new GeometryFactory();
    pointCS = new LiteCoordinateSequence(1, 2);
    point = gf.createPoint(pointCS);
    rectCS = new LiteCoordinateSequence(5, 2);
    rect = gf.createPolygon(gf.createLinearRing(rectCS), null);
    // System.out.println("Crop area: " + geom);
}
 
Example 13
Source File: OmsGeopaparazzi4Converter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static SimpleFeatureCollection media2IdBasedFeatureCollection( IHMConnection connection, IHMProgressMonitor pm )
        throws Exception, IOException, FileNotFoundException {
    try {

        GeometryFactory gf = GeometryUtilities.gf();

        /*
         * create the points fc
         */
        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();

        SimpleFeatureType featureType = GeopaparazziUtilities.getMediaFeaturetype();

        List<Image> imagesList = DaoImages.getImagesList(connection);
        pm.beginTask("Importing media...", imagesList.size());

        for( Image image : imagesList ) {
            Point point = gf.createPoint(new Coordinate(image.getLon(), image.getLat()));
            long ts = image.getTs();
            String dateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(ts));

            Object[] values = new Object[]{point, image.getAltim(), dateTimeString, image.getAzim(), image.getImageDataId()};

            SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
            builder.addAll(values);
            SimpleFeature feature = builder.buildFeature(null);
            newCollection.add(feature);
            pm.worked(1);
        }
        return newCollection;

    } finally {
        pm.done();
    }
}
 
Example 14
Source File: MonitoringPoint.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a featurecollection from a list of monitoringpoints. Based on the position of the
 * points and some of their attributes.
 * 
 * @param monitoringPointsList
 * @return the featurecollection
 */
public SimpleFeatureCollection toFeatureCollection(
        List<MonitoringPoint> monitoringPointsList ) {

    // create the feature type
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    // set the name
    b.setName("monitoringpoints");
    // add a geometry property
    b.add("the_geom", Point.class);
    // add some properties
    b.add("id", Integer.class);
    b.add("relatedid", Integer.class);
    b.add("pfaf", String.class);
    // build the type
    SimpleFeatureType type = b.buildFeatureType();
    // create the feature
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

    GeometryFactory gF = new GeometryFactory();
    /*
     * insert them in inverse order to get them out of the collection in the same order as the
     * list
     */
    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    for( int i = 0; i < monitoringPointsList.size(); i++ ) {
        MonitoringPoint mp = monitoringPointsList.get(monitoringPointsList.size() - i - 1);

        Object[] values = new Object[]{gF.createPoint(mp.getPosition()), mp.getID(),
                mp.getRelatedID(), mp.getPfatstetterNumber().toString()};
        // add the values
        builder.addAll(values);
        // build the feature with provided ID
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + i);
        newCollection.add(feature);
    }

    return newCollection;
}
 
Example 15
Source File: JTSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests various {@code transform} methods. This includes (sometime indirectly):
 *
 * <ul>
 *   <li>{@link JTS#transform(Geometry, CoordinateReferenceSystem)}</li>
 *   <li>{@link JTS#transform(Geometry, CoordinateOperation)}</li>
 *   <li>{@link JTS#transform(Geometry, MathTransform)}</li>
 * </ul>
 *
 * @throws FactoryException if an EPSG code can not be resolved.
 * @throws TransformException if a coordinate can not be transformed.
 */
@Test
public void testTransform() throws FactoryException, TransformException {
    final GeometryFactory factory = new GeometryFactory();
    final Geometry in = factory.createPoint(new Coordinate(5, 6));
    /*
     * Test exception when transforming geometry without CRS.
     */
    try {
        JTS.transform(in, CommonCRS.WGS84.geographic());
        fail("Geometry has no CRS, transform should have failed.");
    } catch (TransformException ex) {
        assertNotNull(ex.getMessage());
    }
    /*
     * Test axes inversion transform.
     */
    in.setUserData(CommonCRS.WGS84.normalizedGeographic());
    Geometry out = JTS.transform(in, CommonCRS.WGS84.geographic());
    assertTrue(out instanceof Point);
    assertEquals(6, ((Point) out).getX(), STRICT);
    assertEquals(5, ((Point) out).getY(), STRICT);
    assertEquals(CommonCRS.WGS84.geographic(), out.getUserData());
    /*
     * Test affine transform. User data must be preserved.
     */
    final AffineTransform2D trs = new AffineTransform2D(1, 0, 0, 1, 10, 20);
    out = JTS.transform(in, trs);
    assertTrue(out instanceof Point);
    assertEquals(15, ((Point) out).getX(), STRICT);
    assertEquals(26, ((Point) out).getY(), STRICT);
}
 
Example 16
Source File: GeoWaveGeometryPrecisionIT.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void testFullPrecision() {
  final GeometryFactory factory = GeometryUtils.GEOMETRY_FACTORY;
  final Geometry[] geometries =
      new Geometry[] {
          factory.createPoint(new Coordinate(12.123456789, -10.987654321)),
          factory.createLineString(
              new Coordinate[] {
                  new Coordinate(123456789.987654321, -123456789.987654321),
                  new Coordinate(987654321.123456789, -987654321.123456789)}),
          factory.createPoint(new Coordinate(0, 0))};
  testPrecision(geometries, geometries, null);
}
 
Example 17
Source File: PolygonCutExtendTool.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
public boolean onToolTouchEvent(MotionEvent event) {
    if (mapView == null || mapView.isClickable()) {
        return false;
    }
    OverlayViewProjection pj = editingViewProjection;

    // handle drawing
    currentX = event.getX();
    currentY = event.getY();

    int action = event.getAction();
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            startGeoPoint = pj.fromPixels(round(currentX), round(currentY));
            pj.toPixels(startGeoPoint, startP);
            endP.set(startP.x, startP.y);

            drawingPath.reset();
            drawingPath.moveTo(startP.x, startP.y);

            lastX = currentX;
            lastY = currentY;
            break;
        case MotionEvent.ACTION_MOVE:
            float dx = currentX - lastX;
            float dy = currentY - lastY;
            if (abs(dx) < 1 && abs(dy) < 1) {
                lastX = currentX;
                lastY = currentY;
                return true;
            }
            Coordinate currentGeoPoint = pj.fromPixels(round(currentX), round(currentY));
            pj.toPixels(currentGeoPoint, tmpP);
            drawingPath.lineTo(tmpP.x, tmpP.y);
            endP.set(tmpP.x, tmpP.y);

            EditManager.INSTANCE.invalidateEditingView();
            break;
        case MotionEvent.ACTION_UP:

            Coordinate endGeoPoint = pj.fromPixels(round(currentX), round(currentY));
            GeometryFactory gf = new GeometryFactory();
            Coordinate startCoord = new Coordinate(startGeoPoint.x, startGeoPoint.y);
            org.locationtech.jts.geom.Point startPoint = gf.createPoint(startCoord);
            Coordinate endCoord = new Coordinate(endGeoPoint.x, endGeoPoint.y);
            org.locationtech.jts.geom.Point endPoint = gf.createPoint(endCoord);
            Envelope env = new Envelope(startCoord, endCoord);
            select(env.getMaxY(), env.getMinX(), env.getMinY(), env.getMaxX(), startPoint, endPoint);
            //            EditManager.INSTANCE.invalidateEditingView();
            break;
    }

    return true;
}
 
Example 18
Source File: GeoWaveAvroFeatureDataAdapterTest.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Test
public void basicTest() throws Exception {

  final GeoWaveAvroFeatureDataAdapter adapter = new GeoWaveAvroFeatureDataAdapter(schema);

  final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
  final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(schema);

  final int numFeatures = 10;

  final List<SimpleFeature> data = new ArrayList<>();
  final Map<Integer, SimpleFeature> dataMap = new HashMap<>();
  // Write data using the whole feature data adapter
  for (int i = 0; i < numFeatures; i++) {

    final Point point = geometryFactory.createPoint(new Coordinate(i, i));

    featureBuilder.set("geometry", point);
    featureBuilder.set("pop", i);
    featureBuilder.set("when", new Date(0));
    featureBuilder.set("whennot", new Date());

    data.add(featureBuilder.buildFeature(Integer.toString(i)));
    dataMap.put(i, data.get(data.size() - 1));
  }

  ingestCannedData(adapter, data);

  final Coordinate[] coordArray = new Coordinate[5];
  coordArray[0] = new Coordinate(-180, -90);
  coordArray[1] = new Coordinate(180, -90);
  coordArray[2] = new Coordinate(180, 90);
  coordArray[3] = new Coordinate(-180, 90);
  coordArray[4] = new Coordinate(-180, -90);
  // read data using the whole feature data adapter
  VectorQueryBuilder bldr =
      VectorQueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(INDEX_NAME);
  bldr =
      bldr.constraints(
          bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(
              new GeometryFactory().createPolygon(coordArray)).build());
  try (final CloseableIterator<SimpleFeature> itr = dataStore.query(bldr.build())) {

    while (itr.hasNext()) {
      final SimpleFeature feat = itr.next();

      final SimpleFeature feature = dataMap.remove(Integer.parseInt(feat.getID()));
      assertEquals(DataUtilities.encodeFeature(feature), DataUtilities.encodeFeature(feat));
    }
    assertTrue(dataMap.isEmpty());
  }
}
 
Example 19
Source File: GeoJSONDecoder.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
protected Point decodePoint(JsonNode node, GeometryFactory fac)
        throws GeoJSONDecodingException {
    Coordinate parsed = decodeCoordinate(requireCoordinates(node));
    return fac.createPoint(parsed);
}
 
Example 20
Source File: PointShape.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * To geometry method
 * @param factory GeometryFactory
 * @return Geometry
 */
@Override
public Geometry toGeometry(GeometryFactory factory){
    Coordinate c = new Coordinate(point.X, point.Y);        
    return factory.createPoint(c);
}