org.locationtech.jts.geom.Geometry Java Examples

The following examples show how to use org.locationtech.jts.geom.Geometry. 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: presto   Author: prestosql   File: GeoFunctions.java    License: Apache License 2.0 6 votes vote down vote up
@Description("Returns the 2D Euclidean area of a geometry")
@ScalarFunction("ST_Area")
@SqlType(DOUBLE)
public static double stArea(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    OGCGeometry geometry = deserialize(input);

    // The Esri geometry library does not support area for geometry collections. We compute the area
    // of collections by summing the area of the individual components.
    GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType());
    if (type == GeometryType.GEOMETRY_COLLECTION) {
        double area = 0.0;
        GeometryCursor cursor = geometry.getEsriGeometryCursor();
        while (true) {
            com.esri.core.geometry.Geometry esriGeometry = cursor.next();
            if (esriGeometry == null) {
                return area;
            }

            area += esriGeometry.calculateArea2D();
        }
    }
    return geometry.getEsriGeometry().calculateArea2D();
}
 
Example #2
Source Project: hortonmachine   Author: TheHortonMachine   File: NwwUtilities.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the lat/long world geometry from two screen corner coordinates.
 * 
 * @param wwd
 *            the {@link WorldWindow} instance.
 * @param x1
 *            the first point screen x.
 * @param y1
 *            the first point screen y.
 * @param x2
 *            the second point screen x.
 * @param y2
 *            the second point screen y.
 * @return the world geomnetry.
 */
public static Geometry getScreenPointsPolygon( WorldWindow wwd, int x1, int y1, int x2, int y2 ) {
    View view = wwd.getView();
    Position p1 = view.computePositionFromScreenPoint(x1, y1);
    Position p2 = view.computePositionFromScreenPoint(x1, y2);
    Position p3 = view.computePositionFromScreenPoint(x2, y2);
    Position p4 = view.computePositionFromScreenPoint(x2, y1);

    Coordinate[] coords = { //
            new Coordinate(p1.longitude.degrees, p1.latitude.degrees), //
            new Coordinate(p2.longitude.degrees, p2.latitude.degrees), //
            new Coordinate(p3.longitude.degrees, p3.latitude.degrees), //
            new Coordinate(p4.longitude.degrees, p4.latitude.degrees)//
    };
    Geometry convexHull = GeometryUtilities.gf().createMultiPoint(coords).convexHull();
    return convexHull;
}
 
Example #3
Source Project: geowave   Author: locationtech   File: GeoWaveGeometryPrecisionIT.java    License: 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 #4
Source Project: snap-desktop   Author: senbox-org   File: ProductAdvancedDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
private AbstractSubsetRegion setGeometry(){
    if(this.readerInspectorExposeParameters != null  && this.readerInspectorExposeParameters.isHasGeoCoding()) {
        final GeoPos geoPos1 = new GeoPos((Double) geoCoordNorthLatSpinner.getValue(),
                (Double) geoCoordWestLongSpinner.getValue());
        final GeoPos geoPos2 = new GeoPos((Double) geoCoordSouthLatSpinner.getValue(),
                (Double) geoCoordEastLongSpinner.getValue());
        GeoCoding geoCoding = this.readerInspectorExposeParameters.getGeoCoding();
        final PixelPos pixelPos1 = geoCoding.getPixelPos(geoPos1, null);
        final PixelPos pixelPos2 = geoCoding.getPixelPos(geoPos2, null);

        final Rectangle.Float region = new Rectangle.Float();
        region.setFrameFromDiagonal(pixelPos1.x, pixelPos1.y, pixelPos2.x, pixelPos2.y);
        final Rectangle.Float productBounds = new Rectangle.Float(0, 0, productWidth, productHeight);
        Rectangle2D finalRegion = productBounds.createIntersection(region);
        Rectangle bounds = new Rectangle((int)finalRegion.getMinX(), (int)finalRegion.getMinY(), (int)(finalRegion.getMaxX() - finalRegion.getMinX()) + 1, (int)(finalRegion.getMaxY() - finalRegion.getMinY()) + 1);
        Geometry geometry = GeoUtils.computeGeometryUsingPixelRegion(geoCoding, bounds);
        return new GeometrySubsetRegion(geometry, 0);
    }
    return null;
}
 
Example #5
Source Project: sldeditor   Author: robward-scisys   File: FieldConfigInlineFeatureTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.FieldConfigInlineFeature#setVisible(boolean)}.
 */
@Test
public void testSetVisible() {
    FieldConfigInlineFeature field =
            new FieldConfigInlineFeature(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, null, true, false));

    boolean expectedValue = true;
    field.setVisible(expectedValue);
    field.createUI();
    field.setVisible(expectedValue);

    expectedValue = false;
    field.setVisible(expectedValue);
}
 
Example #6
Source Project: hortonmachine   Author: TheHortonMachine   File: OmsLW08_NetworkBufferWidthCalculator.java    License: GNU General Public License v3.0 6 votes vote down vote up
private ArrayList<Geometry> getPolygonBetweenLines( ArrayList<SimpleFeature> newLinesFeatures ) {
    ArrayList<Geometry> polygons = new ArrayList<Geometry>();
    for( int i = 0; i < newLinesFeatures.size() - 1; i++ ) {
        SimpleFeature f1 = newLinesFeatures.get(i);
        SimpleFeature f2 = newLinesFeatures.get(i + 1);

        LineString l1 = (LineString) f1.getDefaultGeometry();
        LineString l2 = (LineString) f2.getDefaultGeometry();
        MultiLineString multiLine = gf.createMultiLineString(new LineString[]{l1, l2});

        Geometry convexHull = multiLine.convexHull();
        Geometry buffer = convexHull.buffer(0.1);
        polygons.add(buffer);
    }
    return polygons;
}
 
Example #7
Source Project: java-vector-tile   Author: ElectronicChartCentre   File: VectorTileEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testProvidedAndAutoincrementIds() throws IOException {
    VectorTileEncoder vtm = new VectorTileEncoder(256, 8, true, true);

    Geometry geometry = gf.createPoint(new Coordinate(3, 6));
    Map<String, String> attributes = Collections.singletonMap("key1", "value1");
    vtm.addFeature("DEPCNT", attributes, geometry, 50);

    geometry = gf.createPoint(new Coordinate(3, 6));
    attributes = Collections.singletonMap("key1", "value1");
    vtm.addFeature("DEPCNT", attributes, geometry);

    geometry = gf.createPoint(new Coordinate(3, 6));
    attributes = Collections.singletonMap("key1", "value1");
    vtm.addFeature("DEPCNT", attributes, geometry, 27);

    geometry = gf.createPoint(new Coordinate(3, 6));
    attributes = Collections.singletonMap("key1", "value1");
    vtm.addFeature("DEPCNT", attributes, geometry);

    List<Feature> features = encodeDecodeFeatures(vtm);
    assertEquals(4, features.size());
    assertEquals(50, features.get(0).getId());
    assertEquals(51, features.get(1).getId());
    assertEquals(27, features.get(2).getId());
    assertEquals(52, features.get(3).getId());
}
 
Example #8
Source Project: presto   Author: prestosql   File: GeoFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Description("Returns the reason for why the input geometry is not valid. Returns null if the input is valid.")
@ScalarFunction("geometry_invalid_reason")
@SqlType(VARCHAR)
@SqlNullable
public static Slice invalidReason(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    GeometryCursor cursor = deserialize(input).getEsriGeometryCursor();
    NonSimpleResult result = new NonSimpleResult();
    while (true) {
        com.esri.core.geometry.Geometry geometry = cursor.next();
        if (geometry == null) {
            return null;
        }

        if (!OperatorSimplifyOGC.local().isSimpleOGC(geometry, null, true, result, null)) {
            String reasonText = NON_SIMPLE_REASONS.getOrDefault(result.m_reason, result.m_reason.name());

            if (!(geometry instanceof MultiVertexGeometry)) {
                return utf8Slice(reasonText);
            }

            MultiVertexGeometry multiVertexGeometry = (MultiVertexGeometry) geometry;
            if (result.m_vertexIndex1 >= 0 && result.m_vertexIndex2 >= 0) {
                Point point1 = multiVertexGeometry.getPoint(result.m_vertexIndex1);
                Point point2 = multiVertexGeometry.getPoint(result.m_vertexIndex2);
                return utf8Slice(format("%s at or near (%s %s) and (%s %s)", reasonText, point1.getX(), point1.getY(), point2.getX(), point2.getY()));
            }

            if (result.m_vertexIndex1 >= 0) {
                Point point = multiVertexGeometry.getPoint(result.m_vertexIndex1);
                return utf8Slice(format("%s at or near (%s %s)", reasonText, point.getX(), point.getY()));
            }

            return utf8Slice(reasonText);
        }
    }
}
 
Example #9
Source Project: sldeditor   Author: robward-scisys   File: FieldConfigColourMapTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#getStringValue()}.
 */
@Test
public void testGetStringValue() {

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    ColorMapEntryImpl entry1 = new ColorMapEntryImpl();
    entry1.setColor(ff.literal("#001122"));
    entry1.setLabel("testlabel");
    entry1.setOpacity(ff.literal(0.42));
    entry1.setQuantity(ff.literal(42));
    ColorMap expectedValue = new ColorMapImpl();
    expectedValue.addColorMapEntry(entry1);
    ColorMapEntryImpl entry2 = new ColorMapEntryImpl();
    entry2.setColor(ff.literal("#551122"));
    entry2.setLabel("testlabel2");
    entry2.setOpacity(ff.literal(0.22));
    entry2.setQuantity(ff.literal(12));
    expectedValue.addColorMapEntry(entry2);

    FieldConfigColourMap field =
            new FieldConfigColourMap(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, false));
    field.populateField(expectedValue);

    assertTrue(field.getStringValue().compareTo(EncodeColourMap.encode(expectedValue)) == 0);
}
 
Example #10
Source Project: GeoTriples   Author: LinkedEOData   File: FunctionDisjoint.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<? extends Object> execute(
		List<? extends Object> arguments,List<? extends QLTerm> qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException {
	List<String> valueList = new ArrayList<>();
	
	Geometry geometry1 = computeGeometry(arguments.get(0), qlterms.get(0));
	Geometry geometry2 = computeGeometry(arguments.get(1), qlterms.get(1));
	valueList.add(GTransormationFunctions.disjoint(geometry1, geometry2));
	return valueList;
}
 
Example #11
Source Project: presto   Author: prestosql   File: JtsGeometrySerde.java    License: Apache License 2.0 5 votes vote down vote up
public static Geometry deserialize(Slice shape)
{
    requireNonNull(shape, "shape is null");
    BasicSliceInput input = shape.getInput();
    verify(input.available() > 0);
    GeometrySerializationType type = GeometrySerializationType.getForCode(input.readByte());
    return readGeometry(input, type);
}
 
Example #12
Source Project: hortonmachine   Author: TheHortonMachine   File: FeatureUtilities.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extracts features from a {@link FeatureCollection} into an {@link STRtree}.
 * 
 * @param collection the feature collection.
 * @return the tree containing the features.
 */
public static STRtree featureCollectionToSTRtree( SimpleFeatureCollection collection ) {
    STRtree tree = new STRtree();
    SimpleFeatureIterator featureIterator = collection.features();
    while( featureIterator.hasNext() ) {
        SimpleFeature feature = featureIterator.next();
        Geometry geometry = (Geometry) feature.getDefaultGeometry();
        tree.insert(geometry.getEnvelopeInternal(), feature);
    }
    featureIterator.close();
    return tree;
}
 
Example #13
Source Project: sldeditor   Author: robward-scisys   File: FieldConfigGeometryTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometry#generateExpression()}. Test method for
 * {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometry#populateExpression(java.lang.Object,
 * org.opengis.filter.expression.Expression)}. Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometry#populateField(java.lang.String)}. Test
 * method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometry#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * java.lang.String)}. Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometry#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    FieldConfigGeometry field =
            new FieldConfigGeometry(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, false),
                    "button text");

    field.createUI();
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateField((String) null);
    field.populateExpression((String) null);

    String wktPoint = "POINT( 48.44 -123.37)";

    field.populateField(wktPoint);
    String actualValue = field.getStringValue();
    assertTrue(wktPoint.compareTo(actualValue) == 0);

    String wktPolygon = "POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))";

    field.setTestValue(FieldIdEnum.UNKNOWN, wktPolygon);
    actualValue = field.getStringValue();
    assertTrue(wktPolygon.compareTo(actualValue) == 0);

    String wktLine = "LINESTRING(0 2, 2 0, 8 6)";

    field.populateExpression(wktLine);
    actualValue = field.getStringValue();
    assertTrue(wktLine.compareTo(actualValue) == 0);
}
 
Example #14
Source Project: elasticgeo   Author: ngageoint   File: FilterToElasticHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
private Literal clipToWorld(Literal geometry) {
    if(geometry != null) {
        Geometry g = geometry.evaluate(null, Geometry.class);
        if(g != null) {
            g.apply((GeometryComponentFilter) geom -> geom.apply((CoordinateFilter) coord -> {
                coord.setCoordinate(new Coordinate(clipLon(coord.x), clipLat(coord.y)));
            }));
            geometry = CommonFactoryFinder.getFilterFactory(null).literal(g);

        }
    }

    return geometry;
}
 
Example #15
Source Project: geowave   Author: locationtech   File: GeometryUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testConstraintGeneration() {

  final GeometryFactory gf = new GeometryFactory();
  final Geometry multiPolygon =
      gf.createMultiPolygon(
          new Polygon[] {
              gf.createPolygon(
                  new Coordinate[] {
                      new Coordinate(20.0, 30),
                      new Coordinate(20, 40),
                      new Coordinate(10, 40),
                      new Coordinate(10, 30),
                      new Coordinate(20, 30)}),
              gf.createPolygon(
                  new Coordinate[] {
                      new Coordinate(-9, -2),
                      new Coordinate(-9, -1),
                      new Coordinate(-8, -1),
                      new Coordinate(-8, -2),
                      new Coordinate(-9, -2)})});
  final Constraints constraints = GeometryUtils.basicConstraintsFromGeometry(multiPolygon);
  final List<MultiDimensionalNumericData> results =
      constraints.getIndexConstraints(new IndexImpl(new ExampleNumericIndexStrategy(), null));
  assertEquals(2, results.size());
  assertTrue(Arrays.equals(new double[] {10, 30}, results.get(0).getMinValuesPerDimension()));
  assertTrue(Arrays.equals(new double[] {20, 40}, results.get(0).getMaxValuesPerDimension()));
  assertTrue(Arrays.equals(new double[] {-9, -2}, results.get(1).getMinValuesPerDimension()));
  assertTrue(Arrays.equals(new double[] {-8, -1}, results.get(1).getMaxValuesPerDimension()));
}
 
Example #16
Source Project: presto   Author: prestosql   File: BenchmarkJtsGeometrySerde.java    License: Apache License 2.0 5 votes vote down vote up
private static Geometry fromText(String text)
{
    try {
        return new WKTReader().read(text);
    }
    catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
 
Example #17
Source Project: presto   Author: prestosql   File: TestGeometrySerialization.java    License: Apache License 2.0 5 votes vote down vote up
private static void testJtsSerialization(String wkt)
{
    Geometry jtsGeometry = createJtsGeometry(wkt);
    OGCGeometry esriGeometry = OGCGeometry.fromText(wkt);

    Slice jtsSerialized = JtsGeometrySerde.serialize(jtsGeometry);
    Slice esriSerialized = GeometrySerde.serialize(esriGeometry);
    assertEquals(jtsSerialized, esriSerialized);

    Geometry jtsDeserialized = JtsGeometrySerde.deserialize(jtsSerialized);
    assertGeometryEquals(jtsDeserialized, jtsGeometry);

    OGCGeometry esriDeserialized = GeometrySerde.deserialize(esriSerialized);
    assertGeometryEquals(esriDeserialized, esriGeometry);
}
 
Example #18
Source Project: sldeditor   Author: robward-scisys   File: FieldConfigFeatureTypeConstraintTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#extentUpdated()}.
 */
@Test
public void testExtentUpdated() {
    FieldConfigFeatureTypeConstraint field =
            new FieldConfigFeatureTypeConstraint(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, false));

    field.extentUpdated();

    field.createUI();
    field.extentUpdated();
    // No testing
}
 
Example #19
Source Project: hortonmachine   Author: TheHortonMachine   File: OmsLW09_NetworBufferMergerHolesRemover.java    License: GNU General Public License v3.0 5 votes vote down vote up
private List<Geometry> removeHoles( Geometry cleanPolygon ) {
    ArrayList<Geometry> gl = new ArrayList<Geometry>();
    for( int i = 0; i < cleanPolygon.getNumGeometries(); i++ ) {
        Polygon geometryN = (Polygon) cleanPolygon.getGeometryN(i);
        LineString exteriorRing = geometryN.getExteriorRing();
        Coordinate[] ringCoordinates = exteriorRing.getCoordinates();
        Polygon polygon = gf.createPolygon(ringCoordinates);
        gl.add(polygon);
    }
    return gl;
}
 
Example #20
Source Project: geowave   Author: locationtech   File: ExtractGeometryFilterVisitor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object visit(final Crosses filter, Object data) {
  if (!attributeOfInterest.equals(filter.getExpression1().toString())) {
    return new ExtractGeometryFilterVisitorResult(infinity(), null);
  }
  data = filter.getExpression2().accept(this, data);
  return new ExtractGeometryFilterVisitorResult((Geometry) data, CompareOperation.CROSSES);
}
 
Example #21
Source Project: mapbox-vector-tile-java   Author: wdtinc   File: MvtEncoder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Encode a {@link JtsMvt} to byte[] ready for writing to a file.
 *
 * @param mvt input to encode to bytes
 * @param mvtLayerParams tile creation parameters
 * @param userDataConverter converts {@link Geometry#userData} to MVT feature tags
 * @return bytes ready for writing to a .mvt
 */
public static byte[] encode(JtsMvt mvt, MvtLayerParams mvtLayerParams, IUserDataConverter userDataConverter) {

    // Build MVT
    final VectorTile.Tile.Builder tileBuilder = VectorTile.Tile.newBuilder();

    for(JtsLayer layer : mvt.getLayers()) {
        final Collection<Geometry> layerGeoms = layer.getGeometries();

        // Create MVT layer
        final VectorTile.Tile.Layer.Builder layerBuilder =
                MvtLayerBuild.newLayerBuilder(layer.getName(), mvtLayerParams);
        final MvtLayerProps layerProps = new MvtLayerProps();

        // MVT tile geometry to MVT features
        final List<VectorTile.Tile.Feature> features = JtsAdapter.toFeatures(
                layerGeoms, layerProps, userDataConverter);
        layerBuilder.addAllFeatures(features);
        MvtLayerBuild.writeProps(layerBuilder, layerProps);

        // Build MVT layer
        final VectorTile.Tile.Layer vtl = layerBuilder.build();
        tileBuilder.addLayers(vtl);
    }

    // Build MVT
    return tileBuilder.build().toByteArray();
}
 
Example #22
Source Project: geowave   Author: locationtech   File: GeoWaveFeatureReader.java    License: Apache License 2.0 5 votes vote down vote up
protected long getCountInternal(
    final Geometry jtsBounds,
    final TemporalConstraintsSet timeBounds,
    final Filter filter,
    final Integer limit) {
  final CountQueryIssuer countIssuer = new CountQueryIssuer(filter, limit);
  issueQuery(jtsBounds, timeBounds, countIssuer);
  return countIssuer.count;
}
 
Example #23
Source Project: hortonmachine   Author: TheHortonMachine   File: TinHandler.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void finalCleanup( final double pFinalCleanupDist ) {
    if (isFirstStatsCalculation) {
        throw new IllegalArgumentException("The first round needs to be filtered on all data.");
    }
    pm.beginTask("Creating points indexes...", leftOverCoordinateList.size());
    final STRtree leftOverCoordinatesTree = new STRtree(leftOverCoordinateList.size());
    for( Coordinate c : leftOverCoordinateList ) {
        leftOverCoordinatesTree.insert(new Envelope(c), c);
    }
    pm.done();

    final AtomicInteger removedCount = new AtomicInteger();
    Geometry[] triangles = getTriangles();
    final List<Coordinate> newLeftOverCoordinateList = new ArrayList<Coordinate>();
    pm.beginTask("Final cleanup through triangle to point distance filter...", triangles.length);
    ThreadedRunnable tRun = new ThreadedRunnable(threadsNum, null);
    for( int i = 0; i < triangles.length; i++ ) {
        final Geometry triangle = triangles[i];
        tRun.executeRunnable(new Runnable(){
            public void run() {
                runFinalFilter(leftOverCoordinatesTree, newLeftOverCoordinateList, triangle, pFinalCleanupDist, removedCount);
            }
        });
    }
    tRun.waitAndClose();
    pm.done();

    pm.message("Final points removed from non ground: " + removedCount.get());
    pm.message("Final points left as non ground: " + newLeftOverCoordinateList.size());
    leftOverCoordinateList.clear();
    leftOverCoordinateList.addAll(newLeftOverCoordinateList);
}
 
Example #24
Source Project: sldeditor   Author: robward-scisys   File: InlineCellEditor.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getTableCellEditorComponent(
        JTable table, Object value, boolean isSelected, int row, int column) {

    if ((model != null) && column == model.getGeometryFieldIndex()) {
        WKTDialog wktDialog = new WKTDialog();

        String geometryString = null;
        Object obj = model.getValueAt(row, column);
        if (obj != null) {
            geometryString = obj.toString();
        }

        if (wktDialog.showDialog(geometryString)) {
            String crsCode = model.getSelectedCRSCode();
            Geometry geometry =
                    WKTConversion.convertToGeometry(wktDialog.getWKTString(), crsCode);

            model.updateGeometry(row, geometry);
        }
    } else {
        this.textField.setFont(table.getFont());
        this.textField.setText(value.toString());
        return this.textField;
    }
    return null;
}
 
Example #25
Source Project: geowave   Author: locationtech   File: GeometryHullToolTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRLPolygons() {
  final Geometry leftShape = factory.createPolygon(poly2);

  final Geometry rightShape = factory.createPolygon(poly1);

  assertFalse(GeometryHullTool.clockwise(leftShape.getCoordinates()));
  assertTrue(GeometryHullTool.clockwise(rightShape.getCoordinates()));
  final GeometryHullTool cg = new GeometryHullTool();
  cg.setDistanceFnForCoordinate(new CoordinateCircleDistanceFn());
  final Geometry geo = cg.connect(leftShape, rightShape);
  assertEquals(
      "POLYGON ((39.2 41.2, 39 40.7, 38.7 40.1, 38.4 39.5, 39.3 39.2, 40.6 39.6, 40.8 40.6, 41.2 40.8, 40.5 41, 39.2 41.2))",
      geo.toString());
}
 
Example #26
Source Project: mapbox-vector-tile-java   Author: wdtinc   File: MvtReaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void simpleTest() {
    try {
        // Load multipolygon z0 tile
        final JtsMvt mvt = loadMvt("src/test/resources/vec_tile_test/0/0/0.mvt");

        List<Geometry> geoms = getAllGeometries(mvt);

        // Debug stats of multipolygon
        final JtsGeomStats stats = JtsGeomStats.getStats(geoms);
        LoggerFactory.getLogger(MvtReaderTest.class).info("Stats: {}", stats);
    } catch (IOException e) {
        fail(e.getMessage());
    }
}
 
Example #27
Source Project: GeoTriples   Author: LinkedEOData   File: FunctionCentroidY.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException {

	Geometry geometry = computeGeometry(argument, qlterm);
	return GTransormationFunctions.centroidy(
			(Geometry) geometry);
}
 
Example #28
Source Project: sldeditor   Author: robward-scisys   File: CustomProcessFunction.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** Populate data map. */
private void populateDataMap() {
    dataTypeMap.put("xs:int", Integer.class);
    dataTypeMap.put("xs:double", Double.class);
    dataTypeMap.put("xs:boolean", Boolean.class);
    dataTypeMap.put("xs:float", Float.class);
    dataTypeMap.put("xs:long", Long.class);
    dataTypeMap.put(GEOMETRY_NAME, Geometry.class);
    dataTypeMap.put(BBOX_NAME, ReferencedEnvelope.class);
    dataTypeMap.put(ENUMERATION_NAME, StringBuilder.class);
}
 
Example #29
Source Project: elasticgeo   Author: ngageoint   File: ElasticParserUtilTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGeoPointAsUnrecognizedProperties() {
    final double lat = rand.nextDouble() * 90 - 90;
    final double lon = rand.nextDouble() * 180 - 180;
    properties.put("latD", lat);
    properties.put("lonD", lon);
    final Geometry geometry = parserUtil.createGeometry(properties);
    assertNull(geometry);
}
 
Example #30
Source Project: arctic-sea   Author: 52North   File: SamplingEncoderv20.java    License: Apache License 2.0 5 votes vote down vote up
private String getFeatureType(Geometry geometry) {
    if (geometry instanceof Point || geometry instanceof MultiPoint) {
        return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT;
    } else if (geometry instanceof LineString || geometry instanceof MultiLineString) {
        return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE;
    } else if (geometry instanceof Polygon || geometry instanceof MultiPolygon) {
        return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_SURFACE;
    } else {
        return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_FEATURE;
    }
}