Java Code Examples for org.locationtech.jts.geom.Point

The following examples show how to use org.locationtech.jts.geom.Point. These examples are extracted from open source projects. 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 Project: geowave   Source File: SimpleFeatureCentroidExractorTest.java    License: 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 2
Source Project: geowave   Source File: SingleItemClusterList.java    License: 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 3
Source Project: geopaparazzi   Source File: ShapeWriter.java    License: 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 4
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 5
Source Project: hortonmachine   Source File: TinHandler.java    License: 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 6
Source Project: geowave   Source File: DBScanClusterList.java    License: 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 7
Source Project: hortonmachine   Source File: ASpatialDb.java    License: 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 8
/**
 * 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 9
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 10
@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 11
Source Project: geowave   Source File: DBScanClusterList.java    License: 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 12
Source Project: hortonmachine   Source File: LasUtils.java    License: 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 13
@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 14
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 15
Source Project: geowave   Source File: GeometryDataSetGenerator.java    License: 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 16
Source Project: geowave   Source File: GeometryUtils.java    License: 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 17
Source Project: geowave   Source File: QueryIndexHelperTest.java    License: 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 18
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 19
Source Project: crate   Source File: GeoJSONUtils.java    License: 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 20
private SimpleFeature createPointTextFeature( String typeName, String layerName, int id,
        Coordinate coord, String textString ) {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, Point.class);
    b.add("text", String.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry point = gF.createPoint(coord);
    Object[] values = new Object[]{point, textString, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
 
Example 21
Source Project: presto   Source File: JtsGeometrySerde.java    License: Apache License 2.0 5 votes vote down vote up
private static void writePoint(Point point, SliceOutput output)
{
    output.writeByte(GeometrySerializationType.POINT.code());
    if (!point.isEmpty()) {
        writeCoordinate(point.getCoordinate(), output);
    }
    else {
        output.writeDouble(NaN);
        output.writeDouble(NaN);
    }
}
 
Example 22
private MultiPoint readMultiPoint() throws IOException, ParseException {
    int numGeom = dis.readInt();
    Point[] geoms = new Point[numGeom];
    for( int i = 0; i < numGeom; i++ ) {
        Geometry g = readGeometry();
        if (!(g instanceof Point))
            throw new ParseException(INVALID_GEOM_TYPE_MSG + "MultiPoint");
        geoms[i] = (Point) g;
    }
    return factory.createMultiPoint(geoms);
}
 
Example 23
Source Project: fdb-record-layer   Source File: GeophileSpatial.java    License: Apache License 2.0 5 votes vote down vote up
public static SpatialObject deserializeWKT(Space space, String string, boolean swapLatLong) throws ParseException {
    Geometry geometry = io.get().wktReader().read(string);
    if (swapLatLong) {
        geometry = swapLatLong(geometry);
    }
    return
        geometry instanceof Point
        ? JTS.spatialObject(space, (Point) geometry)
        : JTS.spatialObject(space, geometry);
}
 
Example 24
@Override
public Point getCentroid(final SimpleFeature anObject) {
  final FeatureGeometryHandler handler =
      new FeatureGeometryHandler(anObject.getDefaultGeometryProperty().getDescriptor());
  final Geometry geometry = handler.toIndexValue(anObject).getGeometry();
  final int srid = SimpleFeatureGeometryExtractor.getSRID(anObject);
  final Point point = geometry.getInteriorPoint();
  point.setSRID(srid);
  return point;
}
 
Example 25
Source Project: arctic-sea   Source File: TrajectoryObservation.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create geometry for featureOfInterest from
 * {@link TimeLocationValueTriple}s
 *
 * @param values
 *            The {@link TimeLocationValueTriple}s to check for
 *            featureOfInterest
 */
private void checkForFeature(List<TimeLocationValueTriple> values) {
    AbstractFeature featureOfInterest = getObservationConstellation().getFeatureOfInterest();
    if (featureOfInterest instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
        Coordinate[] coords = getCoordinates(values);
        int srid = 0;
        if (sf.isSetGeometry()) {
            srid = sf.getGeometry().getSRID();
            coords = (Coordinate[]) ArrayUtils.addAll(sf.getGeometry().getCoordinates(), coords);
        } else {
            TimeLocationValueTriple next = values.iterator().next();
            if (next.isSetLocation()) {
                srid = next.getLocation().getSRID();
            }
        }
        try {
            if (coords.length == 1) {
                Point point = new GeometryFactory().createPoint(coords[0]);
                point.setSRID(srid);
                sf.setGeometry(point);
            } else if (coords.length > 1) {
                LineString lineString = new GeometryFactory().createLineString(coords);
                lineString.setSRID(srid);
                sf.setGeometry(lineString);
            }
        } catch (InvalidSridException e) {
            // TODO
        }
    }
}
 
Example 26
Source Project: geowave   Source File: SimpleFeatureCentroidExtractor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Point getCentroid(final SimpleFeature anObject) {
  final FeatureGeometryHandler handler =
      new FeatureGeometryHandler(anObject.getDefaultGeometryProperty().getDescriptor());
  final Geometry geometry = handler.toIndexValue(anObject).getGeometry();
  final int srid = SimpleFeatureGeometryExtractor.getSRID(anObject);
  final Point point = geometry.getCentroid();
  point.setSRID(srid);
  return point;
}
 
Example 27
Source Project: geowave   Source File: TwitterUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SimpleFeatureType createTwitterEventDataType() {

    final SimpleFeatureTypeBuilder simpleFeatureTypeBuilder = new SimpleFeatureTypeBuilder();
    simpleFeatureTypeBuilder.setName(TWITTER_SFT_NAME);

    final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder();

    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_USERID_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_USERNAME_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_TEXT_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_INREPLYTOUSER_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_INREPLYTOSTATUS_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Integer.class).nillable(true).buildDescriptor(
            TWITTER_RETWEETCOUNT_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_LANG_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Date.class).nillable(false).buildDescriptor(
            TWITTER_DTG_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Point.class).nillable(false).buildDescriptor(
            TWITTER_GEOMETRY_ATTRIBUTE));

    return simpleFeatureTypeBuilder.buildFeatureType();
  }
 
Example 28
Source Project: geogson   Source File: JtsPointIterable.java    License: Apache License 2.0 5 votes vote down vote up
public static JtsPointIterable of(final MultiPoint src) {
    return new JtsPointIterable(new PointProvider() {
        @Override
        public int getNumPoints() {
            return src.getNumGeometries();
        }

        @Override
        public Point getPointN(int n) {
            return (Point) src.getGeometryN(n);
        }
    });
}
 
Example 29
Source Project: geowave   Source File: GeoWaveVisibilityIT.java    License: Apache License 2.0 5 votes vote down vote up
private static SimpleFeatureType getType() {
  final SimpleFeatureTypeBuilder bldr = new SimpleFeatureTypeBuilder();
  bldr.setName("testvis");
  final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder();
  bldr.add(attributeTypeBuilder.binding(String.class).buildDescriptor("a"));
  bldr.add(attributeTypeBuilder.binding(String.class).buildDescriptor("b"));
  bldr.add(attributeTypeBuilder.binding(String.class).buildDescriptor("c"));
  bldr.add(attributeTypeBuilder.binding(Point.class).nillable(false).buildDescriptor("geometry"));
  return bldr.buildFeatureType();
}
 
Example 30
Source Project: java-vector-tile   Source File: VectorTileEncoder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * A short circuit clip to the tile extent (tile boundary + buffer) for
 * points to improve performance. This method can be overridden to change
 * clipping behavior. See also {@link #clipGeometry(Geometry)}.
 * 
 * @see https://github.com/ElectronicChartCentre/java-vector-tile/issues/13
 */
protected boolean clipCovers(Geometry geom) {
    if (geom instanceof Point) {
        Point p = (Point) geom;
        return clipGeometry.getEnvelopeInternal().covers(p.getCoordinate());
    }
    return clipGeometry.covers(geom);
}