org.locationtech.jts.geom.Point Java Examples

The following examples show how to use org.locationtech.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: OmsNmeaFeatureReader.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static SimpleFeatureBuilder getNmeaFeatureBuilder() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("nmea");
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("the_geom", Point.class);
    b.add(NmeaGpsPoint.strSpeed, Double.class);
    b.add(NmeaGpsPoint.strAltitude, Double.class);
    b.add(NmeaGpsPoint.strQuality, Double.class);
    b.add(NmeaGpsPoint.strSat, Integer.class);
    b.add(NmeaGpsPoint.strHdop, Double.class);
    b.add(NmeaGpsPoint.strMsl, Double.class);
    b.add(NmeaGpsPoint.strUtctime, String.class);
    b.add(NmeaGpsPoint.strMag_var, Double.class);
    b.add(NmeaGpsPoint.strAngle, Double.class);
    final SimpleFeatureType featureType = b.buildFeatureType();
    SimpleFeatureBuilder nmeaSimpleFeatureBuilder = new SimpleFeatureBuilder(featureType);
    return nmeaSimpleFeatureBuilder;
}
 
Example #2
Source File: PixelExtractionParametersForm.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public Coordinate[] getCoordinates() {
    Coordinate[] coordinates = new Coordinate[coordinateTableModel.getRowCount()];
    for (int i = 0; i < coordinateTableModel.getRowCount(); i++) {
        final Placemark placemark = coordinateTableModel.getPlacemarkAt(i);
        SimpleFeature feature = placemark.getFeature();
        final Date dateTime = (Date) feature.getAttribute(Placemark.PROPERTY_NAME_DATETIME);
        final Coordinate.OriginalValue[] originalValues = PixExOp.getOriginalValues(feature);
        if (placemark.getGeoPos() == null) {
            final Point point = (Point) feature.getDefaultGeometry();
            coordinates[i] = new Coordinate(placemark.getName(), point.getY(), point.getX(),
                                            dateTime, originalValues);
        } else {
            coordinates[i] = new Coordinate(placemark.getName(), placemark.getGeoPos().getLat(),
                                            placemark.getGeoPos().getLon(), dateTime, originalValues);
        }
    }
    return coordinates;
}
 
Example #3
Source File: GeometryDataSetGenerator.java    From geowave with Apache License 2.0 6 votes vote down vote up
private static final List<Point> generatePoints(
    final GeometryFactory factory,
    final Vector2D coordinateOne,
    final Vector2D coordinateTwo,
    final double distanceFactor,
    final int points) {
  final List<Point> results = new ArrayList<>();
  final Random rand = new Random();
  final Vector2D originVec = coordinateTwo.subtract(coordinateOne);
  for (int i = 0; i < points; i++) {
    // HP Fortify "Insecure Randomness" false positive
    // This random number is not used for any purpose
    // related to security or cryptography
    final double factor = rand.nextDouble();
    final Vector2D projectionPoint = originVec.scalarMultiply(factor);
    final double direction = rand.nextGaussian() * distanceFactor;
    final Vector2D orthogonal = new Vector2D(originVec.getY(), -originVec.getX());

    results.add(
        factory.createPoint(
            toCoordinate(
                orthogonal.scalarMultiply(direction).add(projectionPoint).add(coordinateOne))));
  }
  return results;
}
 
Example #4
Source File: GeometryUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
/** farther point in longitudinal axis given a latitude */
private static Point farthestPoint(
    final CoordinateReferenceSystem crs,
    final Point point,
    final double meters) {
  final GeodeticCalculator calc = new GeodeticCalculator(crs);
  calc.setStartingGeographicPoint(point.getX(), point.getY());
  calc.setDirection(90, meters);
  Point2D dest2D = calc.getDestinationGeographicPoint();
  // if this flips over the date line then try the other direction
  if (dest2D.getX() < point.getX()) {
    calc.setDirection(-90, meters);
    dest2D = calc.getDestinationGeographicPoint();
  }
  return point.getFactory().createPoint(new Coordinate(dest2D.getX(), dest2D.getY()));
}
 
Example #5
Source File: QueryIndexHelperTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void testBBOXStatReprojection() {

  // create a EPSG:3785 feature (units in meters)
  final SimpleFeature mercFeat =
      createGeoMercFeature(factory.createPoint(new Coordinate(19971868.8804, 20037508.3428)));

  // convert from EPSG:3785 to EPSG:4326 (convert to degrees lon/lat)
  // approximately 180.0, 85.0
  final SimpleFeature defaultCRSFeat = GeometryUtils.crsTransform(mercFeat, geoType, transform);

  final FeatureBoundingBoxStatistics geoStats =
      new FeatureBoundingBoxStatistics("geometry", geoType, transform);

  geoStats.entryIngested(mercFeat);

  final Coordinate coord = ((Point) defaultCRSFeat.getDefaultGeometry()).getCoordinate();

  // coordinate should match reprojected feature
  assertEquals(coord.x, geoStats.getMinX(), 0.0001);
  assertEquals(coord.x, geoStats.getMaxX(), 0.0001);
  assertEquals(coord.y, geoStats.getMinY(), 0.0001);
  assertEquals(coord.y, geoStats.getMaxY(), 0.0001);
}
 
Example #6
Source File: SingleItemClusterList.java    From geowave with Apache License 2.0 6 votes vote down vote up
public SingleItemClusterList(
    final ByteArray centerId,
    final ClusterItem center,
    final NeighborListFactory<ClusterItem> factory,
    final Map<ByteArray, Cluster> index) {
  super(
      (center.getGeometry() instanceof Point) || center.isCompressed() ? center.getGeometry()
          : null,
      (int) center.getCount(),
      centerId,
      index);

  final Geometry clusterGeo = center.getGeometry();

  compressed = center.isCompressed();

  if (compressed) {
    getClusterPoints(true).add(clusterGeo.getCentroid().getCoordinate());
  }
}
 
Example #7
Source File: OmsGridsGenerator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private void createPoints( CoordinateReferenceSystem crs, GeometryFactory gf, List<LineString> verticals,
        List<LineString> horizontals ) {
    outMap = new DefaultFeatureCollection();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(POINT);
    b.setCRS(crs);
    b.add("the_geom", Point.class);
    b.add("id", Long.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type);

    Geometry gVer = gf.createMultiLineString(verticals.toArray(new LineString[0]));
    Geometry gHor = gf.createMultiLineString(horizontals.toArray(new LineString[0]));

    Geometry intersection = gHor.intersection(gVer);

    long index = 0;
    int numGeometries = intersection.getNumGeometries();
    for( int i = 0; i < numGeometries; i++ ) {
        Geometry geometry = intersection.getGeometryN(i);
        Object[] values = new Object[]{geometry, index++};
        fbuilder.addAll(values);
        SimpleFeature feature = fbuilder.buildFeature(null);
        ((DefaultFeatureCollection) outMap).add(feature);
    }
}
 
Example #8
Source File: SimpleFeatureCentroidExractorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws SchemaException {
  final SimpleFeatureType schema =
      DataUtilities.createType("testGeo", "location:Point:srid=4326,name:String");
  final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors();
  final Object[] defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }

  final SimpleFeature feature =
      SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString());
  final GeometryFactory geoFactory = new GeometryFactory();

  feature.setAttribute("location", geoFactory.createPoint(new Coordinate(-45, 45)));

  final Point point = extractor.getCentroid(feature);
  assertEquals(4326, point.getSRID());
}
 
Example #9
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 #10
Source File: DBScanClusterList.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected double interpolateFactor(final Geometry areaBeingMerged) {
  try {
    if (clusterGeo == null) {
      return 1.0;
    }
    final Geometry intersection = areaBeingMerged.intersection(clusterGeo);
    final double geo2Area = areaBeingMerged.getArea();
    if (intersection != null) {
      if ((intersection instanceof Point) && (areaBeingMerged instanceof Point)) {
        return 0.0;
      } else if (intersection.isEmpty()) {
        return 1.0;
      } else if (geo2Area > 0) {
        return 1.0 - (intersection.getArea() / geo2Area);
      } else {
        return 0.0;
      }
    }
    return 1.0;
  } catch (final Exception ex) {
    LOGGER.warn("Cannot calculate difference of geometries to interpolate size ", ex);
  }
  return 0.0;
}
 
Example #11
Source File: CorrelativeFieldSelectorTest.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testUpdatePointDataSource() throws Exception {
    final BindingContext bindingContext = new BindingContext();
    bindingContext.getPropertySet().addProperties(Property.create("pointDataSource", VectorDataNode.class));
    bindingContext.getPropertySet().addProperties(Property.create("dataField", AttributeDescriptor.class));

    final CorrelativeFieldSelector correlativeFieldSelector = new CorrelativeFieldSelector(bindingContext);
    final Product product = new Product("name", "type", 10, 10);
    product.getVectorDataGroup().add(new VectorDataNode("a", createFeatureType(Geometry.class)));
    product.getVectorDataGroup().add(new VectorDataNode("b", createFeatureType(Point.class)));

    assertEquals(0, correlativeFieldSelector.pointDataSourceList.getItemCount());
    assertEquals(0, correlativeFieldSelector.dataFieldList.getItemCount());

    correlativeFieldSelector.updatePointDataSource(product);

    assertEquals(3, correlativeFieldSelector.pointDataSourceList.getItemCount());
    assertEquals(0, correlativeFieldSelector.dataFieldList.getItemCount());

    correlativeFieldSelector.pointDataSourceProperty.setValue(product.getVectorDataGroup().get("b"));

    assertEquals(3, correlativeFieldSelector.dataFieldList.getItemCount());
}
 
Example #12
Source File: ShapeWriter.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a {@link Shape} representing a {@link Geometry},
 * according to the specified PointTransformation
 * and PointShapeFactory (if relevant).
 * <p>
 * Note that Shapes do not
 * preserve information fragment_about which elements in heterogeneous collections
 * are 1D and which are 2D.
 * For example, a GeometryCollection containing a ring and a
 * disk will render as two disks if Graphics.fill is used,
 * or as two rings if Graphics.draw is used.
 * To avoid this issue use separate shapes for the components.
 *
 * @param geometry the geometry to convert
 * @return a Shape representing the geometry
 */
public DrawableShape toShape(Geometry geometry) {
    if (geometry.isEmpty())
        return new PathShape(new Path());
    else if (geometry instanceof Polygon)
        return toShape((Polygon) geometry);
    else if (geometry instanceof MultiPolygon)
        return toShape((MultiPolygon) geometry);
    else if (geometry instanceof LineString)
        return toShape((LineString) geometry);
    else if (geometry instanceof MultiLineString)
        return toShape((MultiLineString) geometry);
    else if (geometry instanceof Point)
        return toShape((Point) geometry);
    else if (geometry instanceof MultiPoint)
        return toShape((MultiPoint) geometry);
    else if (geometry instanceof GeometryCollection)
        return toShape((GeometryCollection) geometry);

    throw new IllegalArgumentException("Unrecognized Geometry class: " + geometry.getClass());
}
 
Example #13
Source File: TinHandler.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public SimpleFeatureCollection toFeatureCollectionOthers() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("points");
    b.setCRS(crs);

    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    b.add("the_geom", Point.class);
    b.add("elev", Double.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    for( Coordinate c : leftOverCoordinateList ) {
        Object[] values = new Object[]{gf.createPoint(c), c.z};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        newCollection.add(feature);
    }
    return newCollection;
}
 
Example #14
Source File: DBScanClusterList.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected void union(final Geometry otherGeo) {

    if (otherGeo == null) {
      return;
    }
    try {

      if (clusterGeo == null) {
        clusterGeo = otherGeo;
      } else if (clusterGeo instanceof Point) {
        clusterGeo = connectGeometryTool.connect(otherGeo, clusterGeo);
      } else {
        clusterGeo = connectGeometryTool.connect(clusterGeo, otherGeo);
      }
    } catch (final TopologyException ex) {

      LOGGER.error("Union failed due to non-simple geometries", ex);
      clusterGeo =
          connectGeometryTool.createHullFromGeometry(
              clusterGeo,
              Arrays.asList(otherGeo.getCoordinates()),
              false);
    }
  }
 
Example #15
Source File: ASpatialDb.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reproject an envelope.
 * 
 * @param fromEnvelope the original envelope.
 * @param fromSrid the original srid.
 * @param toSrid the destination srid.
 * @return the reprojected Envelope.
 * @throws Exception
 */
public Envelope reproject( Envelope fromEnvelope, int fromSrid, int toSrid ) throws Exception {
    double w = fromEnvelope.getMinX();
    double e = fromEnvelope.getMaxX();
    double s = fromEnvelope.getMinY();
    double n = fromEnvelope.getMaxY();
    String sql = "select ST_Transform( ST_PointFromText('POINT( " + w + " " + s + ")', " + fromSrid + ") , " + toSrid
            + "), ST_Transform( ST_PointFromText('POINT( " + e + " " + n + ")', " + fromSrid + ") , " + toSrid + ")";
    return execOnConnection(connection -> {
        IGeometryParser gp = getType().getGeometryParser();
        try (IHMStatement stmt = connection.createStatement(); IHMResultSet rs = stmt.executeQuery(sql)) {
            if (rs.next()) {
                Geometry llPoint = gp.fromResultSet(rs, 1);
                Geometry urPoint = gp.fromResultSet(rs, 2);
                if (llPoint instanceof Point) {
                    Point ll = (Point) llPoint;
                    Point ur = (Point) urPoint;
                    Envelope newEnv = new Envelope(ll.getX(), ur.getX(), ll.getY(), ur.getY());
                    return newEnv;
                }
            }
            return null;
        }
    });
}
 
Example #16
Source File: CreateInternalDataSource.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds the geometry field.
 *
 * @param b the b
 * @param fieldName the field name
 * @return the attribute descriptor
 */
private AttributeDescriptor addGeometryField(
        ExtendedSimpleFeatureTypeBuilder b, String fieldName) {
    geometryField.setGeometryFieldName(fieldName);
    Class<?> fieldType;
    switch (dsInfo.getGeometryType()) {
        case POLYGON:
            fieldType = MultiPolygon.class;
            break;
        case LINE:
            fieldType = LineString.class;
            break;
        case POINT:
        default:
            fieldType = Point.class;
            break;
    }
    b.setDefaultGeometry(fieldName);
    return b.createAttributeDescriptor(fieldName, fieldType);
}
 
Example #17
Source File: PixelInfoTopComponent.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private void snapToSelectedPin() {
    final Placemark pin = currentView != null ? currentView.getSelectedPin() : null;
    if (pin != null) {
        //todo [multisize_products] replace this very ugly code by using the scene raster transformer - tf 20151113
        PixelPos rasterPos = new PixelPos();
        final Point pinSceneCoords = (Point) pin.getFeature().getDefaultGeometry();
        final Point2D.Double pinSceneCoordsDouble = new Point2D.Double(pinSceneCoords.getX(), pinSceneCoords.getY());
        try {
            currentView.getRaster().getImageToModelTransform().createInverse().transform(pinSceneCoordsDouble, rasterPos);
        } catch (NoninvertibleTransformException e) {
            rasterPos = pin.getPixelPos();
        }
        final int x = MathUtils.floorInt(rasterPos.x);
        final int y = MathUtils.floorInt(rasterPos.y);
        pixelInfoView.updatePixelValues(currentView, x, y, 0, true);
    } else {
        pixelInfoView.updatePixelValues(currentView, -1, -1, 0, false);
    }
}
 
Example #18
Source File: LasUtils.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Convert a record to a feature.
 * 
 * @param r the record to convert.
 * @param featureId an optional feature id, if not available, the id is set to -1.
 * @param crs the crs to apply.
 * @return the feature.
 */
public static SimpleFeature tofeature( LasRecord r, Integer featureId, CoordinateReferenceSystem crs ) {
    final Point point = toGeometry(r);
    double elev = r.z;
    if (!Double.isNaN(r.groundElevation)) {
        elev = r.groundElevation;
    }
    if (featureId == null) {
        featureId = -1;
    }
    final Object[] values = new Object[]{point, featureId, elev, r.intensity, r.classification, r.returnNumber,
            r.numberOfReturns};
    SimpleFeatureBuilder lasFeatureBuilder = getLasFeatureBuilder(crs);
    lasFeatureBuilder.addAll(values);
    final SimpleFeature feature = lasFeatureBuilder.buildFeature(null);
    return feature;
}
 
Example #19
Source File: GmlEncoderv321.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
private void createMultiPointFromJtsGeometry(MultiPoint geom, MultiPointType xbMultiPoint, String id)
        throws EncodingException {
    for (int i = 0; i < geom.getNumGeometries(); i++) {
        Geometry geometry = geom.getGeometryN(i);
        if (geometry instanceof Point) {
            PointType pt = xbMultiPoint.addNewPointMember().addNewPoint();
            pt.setId(id + "_" + i);
            createPointFromJtsGeometry((Point) geometry, pt);
        }
    }
}
 
Example #20
Source File: AbstractMultiPointCoverageTypeEncoder.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
private void encodeMultiPointDomain(DiscreteCoverageType dct, PointValueLists pointValues)
        throws EncodingException {
    MultiPointDomainDocument mpdd = MultiPointDomainDocument.Factory.newInstance();
    DomainSetType mpdst = mpdd.addNewMultiPointDomain();
    GeometryFactory factory = pointValues.getPoints().get(0).getFactory();
    MultiPoint multiPoint = factory.createMultiPoint(pointValues.getPoints().toArray(new Point[0]));
    EncodingContext ec =
            EncodingContext.of(XmlBeansEncodingFlags.GMLID, IdGenerator.generate(multiPoint.toString()))
                    .with(XmlBeansEncodingFlags.PROPERTY_TYPE, true);
    XmlObject encodedGeometry = encodeGML(multiPoint, ec);
    mpdst.addNewAbstractGeometry().set(encodedGeometry);
    substitute(mpdst.getAbstractGeometry(), encodedGeometry);
    dct.setDomainSet(mpdst);
}
 
Example #21
Source File: GeoJSONUtils.java    From crate with Apache License 2.0 5 votes vote down vote up
public Map<String, Object> convert(Geometry geometry) {
    HashMap<String, Object> builder = new HashMap<>();

    if (geometry instanceof Point) {
        builder.put(TYPE_FIELD, POINT);
        builder.put(COORDINATES_FIELD, extract((Point) geometry));
    } else if (geometry instanceof MultiPoint) {
        builder.put(TYPE_FIELD, MULTI_POINT);
        builder.put(COORDINATES_FIELD, extract((MultiPoint) geometry));
    } else if (geometry instanceof LineString) {
        builder.put(TYPE_FIELD, LINE_STRING);
        builder.put(COORDINATES_FIELD, extract((LineString) geometry));
    } else if (geometry instanceof MultiLineString) {
        builder.put(TYPE_FIELD, MULTI_LINE_STRING);
        builder.put(COORDINATES_FIELD, extract((MultiLineString) geometry));
    } else if (geometry instanceof Polygon) {
        builder.put(TYPE_FIELD, POLYGON);
        builder.put(COORDINATES_FIELD, extract((Polygon) geometry));
    } else if (geometry instanceof MultiPolygon) {
        builder.put(TYPE_FIELD, MULTI_POLYGON);
        builder.put(COORDINATES_FIELD, extract((MultiPolygon) geometry));
    } else if (geometry instanceof GeometryCollection) {
        GeometryCollection geometryCollection = (GeometryCollection) geometry;
        int size = geometryCollection.getNumGeometries();
        List<Map<String, Object>> geometries = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            geometries.add(convert(geometryCollection.getGeometryN(i)));
        }
        builder.put(TYPE_FIELD, GEOMETRY_COLLECTION);
        builder.put(GEOMETRIES_FIELD, geometries);
    } else {
        throw new IllegalArgumentException(String.format(Locale.ENGLISH,
            "Cannot extract coordinates from geometry %s", geometry.getGeometryType()));
    }
    return Collections.unmodifiableMap(builder);
}
 
Example #22
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a Geometry class for the given dimensionality.
 *
 * @param dimensionality
 */
private Class<?> getGeometryForDimensionality(int dimensionality) {
    if (dimensionality == 1) {
        return Point.class;
    }
    if (dimensionality == 2) {
        return LineString.class;
    }
    return Polygon.class;
}
 
Example #23
Source File: RandomGeometryBuilder.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
public MultiPoint createRandomMultiPoint() {
    Point[] points = new Point[numGeometries];
    for (int i=0; i<numGeometries; i++) {
        points[i] = createRandomPoint();
    }
    return geometryFactory.createMultiPoint(points);
}
 
Example #24
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 #25
Source File: JtsLayerTest.java    From mapbox-vector-tile-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddGeometry() {
    String layerName = "Points of Interest";
    List<Geometry> geometries = new ArrayList<>();

    Point point = createPoint(new int[]{51, 0});

    JtsLayer layer = new JtsLayer(layerName, geometries);
    layer.getGeometries().add(point);

    assertTrue(layer.getGeometries().contains(point));
}
 
Example #26
Source File: GeopaparazziUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static SimpleFeatureType getSimpleNotesfeatureType() {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("gpsimplenotes"); //$NON-NLS-1$
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", Point.class); //$NON-NLS-1$
        b.add(NOTES_textFN, String.class);
        b.add(NOTES_descFN, String.class);
        b.add(NOTES_tsFN, String.class);
        b.add(NOTES_altimFN, Double.class);
        b.add(NOTES_dirtyFN, Integer.class);
        SimpleFeatureType featureType = b.buildFeatureType();
        return featureType;
    }
 
Example #27
Source File: ElasticParserUtilTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGeoShapePointString() {
    Point geom = rgb.createRandomPoint();
    final Map<String, Object> map = new HashMap<>();
    final List<String> coords = new ArrayList<>();
    coords.add(String.valueOf(geom.getX()));
    coords.add(String.valueOf(geom.getY()));
    map.put("coordinates", coords);
    map.put("type", "Point");
    assertTrue(parserUtil.createGeometry(map).equalsExact(geom, 1e-9));
}
 
Example #28
Source File: GeopaparazziUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static SimpleFeatureType getMediaFeaturetype() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("geopaparazzimediapoints");
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("the_geom", Point.class);

    b.add(IMAGES_altimFN, String.class);
    b.add(IMAGES_tsFN, String.class);
    b.add(IMAGES_azimFN, Double.class);
    b.add(IMAGES_imageidFN, Long.class);
    SimpleFeatureType featureType = b.buildFeatureType();
    return featureType;
}
 
Example #29
Source File: SpatialiteWKBWriter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private void writePoint( Point pt, OutStream os ) throws IOException {
    if (pt.getCoordinateSequence().size() == 0)
        throw new IllegalArgumentException("Empty Points cannot be represented in WKB");
    // writeByteOrder(os);
    writeGeometryType(WKBConstants.wkbPoint, pt, os);
    writeCoordinateSequence(pt.getCoordinateSequence(), false, os);
}
 
Example #30
Source File: PolygonAreaCalculator.java    From geowave with Apache License 2.0 5 votes vote down vote up
public double getAreaSimple(final Geometry polygon) throws Exception {
  final Point centroid = polygon.getCentroid();
  final CoordinateReferenceSystem equalAreaCRS = lookupUtmCrs(centroid.getY(), centroid.getX());

  final MathTransform transform =
      CRS.findMathTransform(DefaultGeographicCRS.WGS84, equalAreaCRS, true);

  final Geometry transformedPolygon = JTS.transform(polygon, transform);

  return transformedPolygon.getArea() * SQM_2_SQKM;
}