Java 类com.vividsolutions.jts.geom.LineString 实例源码

项目:sumo    文件:JTSUtil.java   
/** */
public static Geometry flatten (GeometryCollection gc) {
    final List<Point> points = new LinkedList<Point>();
    final List<LineString> lines = new LinkedList<LineString>();
    final List<Polygon> polygons = new LinkedList<Polygon>();
    gc.apply(new GeometryFilter() {
            public void filter (Geometry geom) {
                if (geom instanceof Point) {
                    points.add((Point)geom);
                } else if (geom instanceof LineString) {
                    lines.add((LineString)geom);
                } else if (geom instanceof Polygon) {
                    polygons.add((Polygon)geom);
                }
            }
        });
    if (!polygons.isEmpty()) {
        return gc.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons));
    } else if (!lines.isEmpty()) {
        return gc.getFactory().createMultiLineString(GeometryFactory.toLineStringArray(lines));
    } else {
        return gc.getFactory().createMultiPoint(GeometryFactory.toPointArray(points));
    }
}
项目:elasticsearch_my    文件:GeoJSONShapeParserTests.java   
public void testParseLineString() throws IOException {
    XContentBuilder lineGeoJson = XContentFactory.jsonBuilder()
            .startObject()
                .field("type", "LineString")
                .startArray("coordinates")
                .startArray().value(100.0).value(0.0).endArray()
                .startArray().value(101.0).value(1.0).endArray()
                .endArray()
            .endObject();

    List<Coordinate> lineCoordinates = new ArrayList<>();
    lineCoordinates.add(new Coordinate(100, 0));
    lineCoordinates.add(new Coordinate(101, 1));

    LineString expected = GEOMETRY_FACTORY.createLineString(
            lineCoordinates.toArray(new Coordinate[lineCoordinates.size()]));
    assertGeometryEquals(jtsGeom(expected), lineGeoJson);
}
项目:fpm    文件:LongLineSplitter.java   
public static List<LineString> split(LineString given, int maxPoint) {
    List<LineString> result = newArrayList();
    Coordinate[] coordinates = given.getCoordinates();
    int current = 0;
    while (current < coordinates.length) {
        int end = current + maxPoint - 1;
        if (coordinates.length - end < 2) {
            result.add(gf.createLineString(Arrays.copyOfRange(coordinates, current, coordinates.length)));
            return result;
        }
        else {
            result.add(gf.createLineString(Arrays.copyOfRange(coordinates, current, end + 1)));
            current = end;
        }
    }
    throw new IllegalStateException("Unexpected");
}
项目:fpm    文件:LongLineSplitterTest.java   
@Test
public void should_split_long_line() {
    Polygon polygon = polygon(
            new Coordinate(0.0, 0.0),
            new Coordinate(1.0, 0.0),
            new Coordinate(1.0, 1.0),
            new Coordinate(0.0, 1.0),
            new Coordinate(0.0, 0.0));

    List<LineString> lines = LongLineSplitter.split(polygon.getExteriorRing(), 3);

    assertThat(lines).containsExactly(
            linestring(
                    new Coordinate(0.0, 0.0),
                    new Coordinate(1.0, 0.0),
                    new Coordinate(1.0, 1.0)),
            linestring(
                    new Coordinate(1.0, 1.0),
                    new Coordinate(0.0, 1.0),
                    new Coordinate(0.0, 0.0)));
}
项目:sumo    文件:ClipProcess.java   
@Override
public void filter(Geometry geom) {
    if(geom instanceof LineString) {
        LineString ls = ((LineString) geom);

        // look for the original line containing this one
        LineString original = getOriginator(ls);
        if(original == null) {
            LOGGER.log(java.util.logging.Level.WARNING, "Could not find the original line from which the output line " + geom + " originated");
            return;
        }

        try {
            applyElevations(ls, original, false);
        } catch(ClippingException e) {
            // fine, let's try with the more expensive way then
            applyElevations(ls, original, true);
        }
    }

}
项目:elasticsearch_my    文件:LineStringBuilder.java   
@Override
public Shape build() {
    Coordinate[] coordinates = this.coordinates.toArray(new Coordinate[this.coordinates.size()]);
    Geometry geometry;
    if(wrapdateline) {
        ArrayList<LineString> strings = decompose(FACTORY, coordinates, new ArrayList<LineString>());

        if(strings.size() == 1) {
            geometry = strings.get(0);
        } else {
            LineString[] linestrings = strings.toArray(new LineString[strings.size()]);
            geometry = FACTORY.createMultiLineString(linestrings);
        }

    } else {
        geometry = FACTORY.createLineString(coordinates);
    }
    return jtsGeometry(geometry);
}
项目:elasticsearch_my    文件:ElasticsearchGeoAssertions.java   
public static void assertEquals(Geometry s1, Geometry s2) {
    if(s1 instanceof LineString && s2 instanceof LineString) {
        assertEquals((LineString) s1, (LineString) s2);

    } else if (s1 instanceof Polygon && s2 instanceof Polygon) {
        assertEquals((Polygon) s1, (Polygon) s2);

    } else if (s1 instanceof MultiPoint && s2 instanceof MultiPoint) {
        Assert.assertEquals(s1, s2);

    } else if (s1 instanceof MultiPolygon && s2 instanceof MultiPolygon) {
        assertEquals((MultiPolygon) s1, (MultiPolygon) s2);

    } else if (s1 instanceof MultiLineString && s2 instanceof MultiLineString) {
        assertEquals((MultiLineString) s1, (MultiLineString) s2);

    } else {
        throw new RuntimeException("equality of shape types not supported [" + s1.getClass().getName() + " and " + s2.getClass().getName() + "]");
    }
}
项目:graphium    文件:WayGraphModelFactory.java   
@Override
public IWaySegment newSegment(long id, LineString geometry, float length,
        String name, String streetType, long wayId, long startNodeId,
        int startNodeIndex, long endNodeId, int endNodeIndex,
        List<IWaySegmentConnection> connections) {
    IWaySegment segment = new WaySegment();
    segment.setId(id);
    segment.setGeometry(geometry);
    segment.setLength(length);
    segment.setName(name);
    segment.setStreetType(streetType);
    segment.setWayId(wayId);
    segment.setStartNodeId(startNodeId);
    segment.setStartNodeIndex(startNodeIndex);
    segment.setEndNodeId(endNodeId);
    segment.setEndNodeIndex(endNodeIndex);
    segment.setCons(connections);
    segment.setEndNodeIndex(endNodeIndex);
    return segment;
}
项目:graphium    文件:WayGraphModelFactory.java   
@Override
public IWaySegment newSegment(long id, LineString geometry, float length,
        String name, String streetType, long wayId, long startNodeId,
        int startNodeIndex, long endNodeId, int endNodeIndex,
        List<IWaySegmentConnection> connections,
        Map<String, String> tags, Map<String, List<ISegmentXInfo>> xInfo) {
    IWaySegment segment = new WaySegment();
    segment.setId(id);
    segment.setGeometry(geometry);
    segment.setLength(length);
    segment.setName(name);
    segment.setStreetType(streetType);
    segment.setWayId(wayId);
    segment.setStartNodeId(startNodeId);
    segment.setStartNodeIndex(startNodeIndex);
    segment.setEndNodeId(endNodeId);
    segment.setEndNodeIndex(endNodeIndex);
    segment.setCons(connections);
    segment.setEndNodeIndex(endNodeIndex);
    segment.setTags(tags);
    segment.setXInfo(mergeXInfoList(xInfo));
    return segment;
}
项目:graphium    文件:WayGraphModelFactory.java   
@Override
public IWaySegment newSegment(long id, LineString geometry,
        float length, String name, short maxSpeedTow, short maxSpeedBkw,
        Short speedCalcTow, Short speedCalcBkw, short lanesTow,
        short lanesBkw, FuncRoadClass frc, FormOfWay formOfWay, String streetType,
        long wayId, long startNodeId, int startNodeIndex, long endNodeId,
        int endNodeIndex, Set<Access> accessTow, Set<Access> accessBkw,
        Boolean tunnel, Boolean bridge, Boolean urban, Date timestamp,
        List<IWaySegmentConnection> startNodeCons,
        List<IWaySegmentConnection> endNodeCons) {
    return new WaySegment(id, geometry, length, name, maxSpeedTow,
            maxSpeedBkw, speedCalcTow, speedCalcBkw, lanesTow, lanesBkw,
            frc, formOfWay, streetType, wayId, startNodeId, startNodeIndex,
            endNodeId, endNodeIndex, accessTow, accessBkw, tunnel, bridge,
            urban, timestamp, adaptConns(startNodeCons, endNodeCons), null, null);
}
项目:graphium    文件:WayGraphModelFactory.java   
@Override
public IWaySegment newSegment(long id, LineString geometry,
                              float length, String name, short maxSpeedTow, short maxSpeedBkw,
                              Short speedCalcTow, Short speedCalcBkw, short lanesTow,
                              short lanesBkw, FuncRoadClass frc, FormOfWay formOfWay, String streetType,
                              long wayId, long startNodeId, int startNodeIndex, long endNodeId,
                              int endNodeIndex, Set<Access> accessTow, Set<Access> accessBkw,
                              Boolean tunnel, Boolean bridge, Boolean urban, Date timestamp,
                              List<IWaySegmentConnection> startNodeCons,
                              List<IWaySegmentConnection> endNodeCons,
                              Map<String, String> tags, Map<String, List<ISegmentXInfo>> xInfo) {
    return new WaySegment(id, geometry, length, name, maxSpeedTow,
            maxSpeedBkw, speedCalcTow, speedCalcBkw, lanesTow, lanesBkw,
            frc, formOfWay, streetType, wayId, startNodeId, startNodeIndex,
            endNodeId, endNodeIndex, accessTow, accessBkw, tunnel, bridge,
            urban, timestamp, adaptConns(startNodeCons, endNodeCons), tags, xInfo);
}
项目:graphium    文件:BaseWaySegment.java   
public BaseWaySegment(long id, LineString geometry, float length, String name, String streetType, long wayId,
        long startNodeId, int startNodeIndex, long endNodeId, int endNodeIndex,
        List<IWaySegmentConnection> cons,
        Map<String, String> tags, Map<String, List<ISegmentXInfo>> xInfo) {
    super(id, xInfo,cons);
    this.geometry = geometry;
    this.length = length;
    this.name = name;
    this.streetType = streetType;
    this.wayId = wayId;
    this.startNodeId = startNodeId;
    this.startNodeIndex = startNodeIndex;
    this.endNodeId = endNodeId;
    this.endNodeIndex = endNodeIndex;
    this.tags = tags;
    this.xInfo = xInfo;
}
项目:graphium    文件:WaySegment.java   
public WaySegment(long id, LineString geometry, float length, String name,
        short maxSpeedTow, short maxSpeedBkw, Short speedCalcTow,
        Short speedCalcBkw, short lanesTow, short lanesBkw, FuncRoadClass frc, FormOfWay formOfWay,
        String streetType, long wayId, long startNodeId,
        int startNodeIndex, long endNodeId, int endNodeIndex,
        Set<Access> accessTow, Set<Access> accessBkw, Boolean tunnel, Boolean bridge, Boolean urban,
        Date timestamp, List<IWaySegmentConnection> cons, Map<String, String> tags,
        Map<String, List<ISegmentXInfo>> xInfo) {
    super(id, geometry, length, name, streetType, wayId, startNodeId, startNodeIndex, 
            endNodeId, endNodeIndex, cons, tags, xInfo);
    this.maxSpeedTow = maxSpeedTow;
    this.maxSpeedBkw = maxSpeedBkw;
    this.speedCalcTow = speedCalcTow;
    this.speedCalcBkw = speedCalcBkw;
    this.lanesTow = lanesTow;
    this.lanesBkw = lanesBkw;
    this.frc = frc;
    this.formOfWay = formOfWay;
    this.accessTow = accessTow;
    this.accessBkw = accessBkw;
    this.tunnel = tunnel;
    this.bridge = bridge;
    this.urban = urban;
    this.timestamp = timestamp;
}
项目:graphium    文件:BaseWaySegmentDTOImpl.java   
public BaseWaySegmentDTOImpl(long id, LineString geometry, String name,
        String streetType, long wayId, long startNodeIndex,
        long startNodeId, long endNodeIndex, long endNodeId,
        Map<String,String> tags,
        List<IBaseSegmentConnectionDTO> connection, Map<String,List<ISegmentXInfoDTO>> xInfo) {
    super(id,connection,xInfo);
    this.geometry = geometry;
    this.name = name;
    this.streetType = streetType;
    this.wayId = wayId;
    this.startNodeIndex = startNodeIndex;
    this.startNodeId = startNodeId;
    this.endNodeIndex = endNodeIndex;
    this.endNodeId = endNodeId;
    this.tags = tags;
}
项目:graphium    文件:WaySegmentDTOImpl.java   
public WaySegmentDTOImpl(long id, LineString geometry, String name,
                         short maxSpeedTow, short maxSpeedBkw, short calcSpeedTow,
                         short calcSpeedBkw, short lanesTow, short lanesBkw, short frc, String formOfWay,
                         String streetType, long wayId, long startNodeIndex,
                         long startNodeId, long endNodeIndex, long endNodeId, Set<Access> accessTow,
                         Set<Access> accessBkw, boolean tunnel, boolean bridge, boolean urban,
                         Map<String,String> tags,
                         List<IBaseSegmentConnectionDTO> connection, Map<String,List<ISegmentXInfoDTO>> xInfo) {
    super(id, geometry, name, streetType, wayId, startNodeIndex, startNodeId, endNodeIndex, endNodeId, tags, connection, xInfo);
    this.maxSpeedTow = maxSpeedTow;
    this.maxSpeedBkw = maxSpeedBkw;
    this.calcSpeedTow = calcSpeedTow;
    this.calcSpeedBkw = calcSpeedBkw;
    this.lanesTow = lanesTow;
    this.lanesBkw = lanesBkw;
    this.frc = frc;
    this.formOfWay = formOfWay;
    this.accessTow = accessTow;
    this.accessBkw = accessBkw;
    this.tunnel = tunnel;
    this.bridge = bridge;
    this.urban = urban;
}
项目:fpm    文件:LongLineSplitterTest.java   
@Test
public void should_return_same_geom_if_necessary() {
    LineString linestring = linestring(
            new Coordinate(0.0, 0.0),
            new Coordinate(1.0, 0.0),
            new Coordinate(1.0, 1.0));

    List<LineString> lines = LongLineSplitter.split(linestring, 3);

    assertThat(lines).containsExactly(
            linestring(
                    new Coordinate(0.0, 0.0),
                    new Coordinate(1.0, 0.0),
                    new Coordinate(1.0, 1.0)));
    assertThat(lines).isEqualTo(LongLineSplitter.split(linestring, 4));
    assertThat(lines).isEqualTo(LongLineSplitter.split(linestring, 5));
}
项目:fpm    文件:LongLineSplitterTest.java   
@Test
public void should_split_linestring() {
    LineString linestring = linestring(
            new Coordinate(0.0, 0.0),
            new Coordinate(1.0, 0.0),
            new Coordinate(1.0, 1.0));

    List<LineString> lines = LongLineSplitter.split(linestring, 2);

    assertThat(lines).containsExactly(
            linestring(
                    new Coordinate(0.0, 0.0),
                    new Coordinate(1.0, 0.0)),
            linestring(
                    new Coordinate(1.0, 0.0),
                    new Coordinate(1.0, 1.0)));
}
项目:Elasticsearch    文件:BaseLineStringBuilder.java   
@Override
public Shape build() {
    Coordinate[] coordinates = points.toArray(new Coordinate[points.size()]);
    Geometry geometry;
    if(wrapdateline) {
        ArrayList<LineString> strings = decompose(FACTORY, coordinates, new ArrayList<LineString>());

        if(strings.size() == 1) {
            geometry = strings.get(0);
        } else {
            LineString[] linestrings = strings.toArray(new LineString[strings.size()]);
            geometry = FACTORY.createMultiLineString(linestrings);
        }

    } else {
        geometry = FACTORY.createLineString(coordinates);
    }
    return jtsGeometry(geometry);
}
项目:vt-support    文件:JtsAdapter.java   
/**
 * Get the MVT type mapping for the provided JTS Geometry.
 *
 * @param geometry JTS Geometry to get MVT type for
 * @return MVT type for the given JTS Geometry, may return
 * {@link uk.os.vt.mvt.VectorTile.Tile.GeomType#UNKNOWN}
 */
public static VectorTile.Tile.GeomType toGeomType(Geometry geometry) {
  VectorTile.Tile.GeomType result = VectorTile.Tile.GeomType.UNKNOWN;

  if (geometry instanceof Point
      || geometry instanceof MultiPoint) {
    result = VectorTile.Tile.GeomType.POINT;

  } else if (geometry instanceof LineString
      || geometry instanceof MultiLineString) {
    result = VectorTile.Tile.GeomType.LINESTRING;

  } else if (geometry instanceof Polygon
      || geometry instanceof MultiPolygon) {
    result = VectorTile.Tile.GeomType.POLYGON;
  }

  return result;
}
项目:vt-support    文件:JtsGeomStats.java   
private static FeatureStats polyStats(Geometry geom) {
  final FeatureStats featureStats = new FeatureStats();

  for (int i = 0; i < geom.getNumGeometries(); ++i) {
    final Polygon nextPoly = (Polygon) geom.getGeometryN(i);

    // Stats: exterior ring
    final LineString exteriorRing = nextPoly.getExteriorRing();
    featureStats.totalPts += exteriorRing.getNumPoints();
    featureStats.repeatedPts += checkRepeatedPoints2d(exteriorRing);

    // Stats: interior rings
    for (int ringIndex = 0; ringIndex < nextPoly.getNumInteriorRing(); ++ringIndex) {

      final LineString nextInteriorRing = nextPoly.getInteriorRingN(ringIndex);
      featureStats.totalPts += nextInteriorRing.getNumPoints();
      featureStats.repeatedPts += checkRepeatedPoints2d(nextInteriorRing);
    }
  }

  return featureStats;
}
项目:vt-support    文件:JtsGeomStats.java   
private static int checkRepeatedPoints2d(LineString lineString) {
  int repeatedPoints = 0;

  final CoordinateSequence coordSeq = lineString.getCoordinateSequence();
  Coordinate nextCoord = null;
  Coordinate prevCoord;
  for (int i = 0; i < coordSeq.size(); ++i) {
    prevCoord = nextCoord;
    nextCoord = coordSeq.getCoordinate(i);
    if (nextCoord.equals(prevCoord)) {
      ++repeatedPoints;
    }
  }

  return repeatedPoints;
}
项目:openrouteservice    文件:RealTrafficDataProvider.java   
private boolean isEdgesMatched(int edgeId, RoutingProfile rp4tmc, int newEdgeId, RoutingProfile rp4routing){

    // check the validity of the edge
    //boolean flag1 = rp4tmc.getGraphhopper().getGraphHopperStorage().isValidEdge(edgeId);
    //boolean flag2 = rp4routing.getGraphhopper().getGraphHopperStorage().isValidEdge(newEdgeId); // Runge: it has been commented out as the meaning of this check is not entirely clear

    if (EdgeIterator.Edge.isValid(edgeId) && EdgeIterator.Edge.isValid(newEdgeId)){
        LineString edge_geom  = (LineString) rp4tmc.getEdgeGeometry(edgeId, 3, Integer.MIN_VALUE); 
        LineString new_edge_geom = (LineString) rp4routing.getEdgeGeometry(newEdgeId, 3, Integer.MIN_VALUE);

        if (edge_geom.intersects(new_edge_geom)){               
           return true;            
        }
    }

    return false;       
}
项目:openrouteservice    文件:JTS.java   
/**
 * Removes collinear vertices from the provided {@link Geometry}.
 * 
 * <p>
 * For the moment this implementation only accepts, {@link Polygon}, {@link LineString} and {@link MultiPolygon} It will throw an exception if the
 * geometry is not one of those types
 * 
 * @param g the instance of a {@link Geometry} to remove collinear vertices from.
 * @return a new instance of the provided {@link Geometry} without collinear vertices.
 */
public static Geometry removeCollinearVertices(final Geometry g) {
    if (g == null) {
        throw new NullPointerException("The provided Geometry is null");
    }
    if (g instanceof LineString) {
        return removeCollinearVertices((LineString) g);
    } else if (g instanceof Polygon) {
        return removeCollinearVertices((Polygon) g);
    } else if (g instanceof MultiPolygon) {
        MultiPolygon mp = (MultiPolygon) g;
        Polygon[] parts = new Polygon[mp.getNumGeometries()];
        for (int i = 0; i < mp.getNumGeometries(); i++) {
            Polygon part = (Polygon) mp.getGeometryN(i);
            part = removeCollinearVertices(part);
            parts[i] = part;
        }

        return g.getFactory().createMultiPolygon(parts);
    }

    throw new IllegalArgumentException(
            "This method can work on LineString, Polygon and Multipolygon: " + g.getClass());
}
项目:openrouteservice    文件:JsonLocationsRequestParser.java   
private static void checkSearchRadius(Geometry geom, double value) throws Exception
{
    if (geom instanceof Point)
    {
        if (LocationsServiceSettings.getMaximumSearchRadiusForPoints() > 0 && LocationsServiceSettings.getMaximumSearchRadiusForPoints() < value)
            throw new ParameterOutOfRangeException(LocationsErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "radius", Double.toString(value), Double.toString(LocationsServiceSettings.getMaximumSearchRadiusForPoints()));
    }
    else if (geom instanceof LineString)
    {
        if (LocationsServiceSettings.getMaximumSearchRadiusForLinestrings() > 0 && LocationsServiceSettings.getMaximumSearchRadiusForLinestrings() < value)
            throw new ParameterOutOfRangeException(LocationsErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "radius", Double.toString(value), Double.toString(LocationsServiceSettings.getMaximumSearchRadiusForLinestrings()));
    }
    else if (geom instanceof Polygon)
    {
        if (LocationsServiceSettings.getMaximumSearchRadiusForPolygons() > 0 && LocationsServiceSettings.getMaximumSearchRadiusForPolygons() < value)
            throw new ParameterOutOfRangeException(LocationsErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "radius", Double.toString(value), Double.toString(LocationsServiceSettings.getMaximumSearchRadiusForPolygons()));
    }
}
项目:openrouteservice    文件:GeometryJSON.java   
public static JSONArray toJSON(Geometry geom, StringBuffer buffer) throws Exception
{
    if (geom instanceof Polygon)
    {
        return toJSON((Polygon)geom);
    }
    else if (geom instanceof LineString)
    {
        return toJSON((LineString)geom, false);
    }
    else if (geom instanceof Point)
    {
        return toJSON((Point)geom);
    }
    else if (geom instanceof MultiPolygon)
    {
        return toJSON((MultiPolygon)geom);
    }
    else 
    {
        throw new Exception("toJSON function is not implemented for " + geom.getGeometryType());
    }
}
项目:openrouteservice    文件:GeometryJSON.java   
public static JSONArray toJSON(Polygon poly)
{
    JSONArray coords = new JSONArray(1 + poly.getNumInteriorRing());

    LineString shell = poly.getExteriorRing();

    boolean inverse = shell.getNumPoints() > 1 ? !CoordinateSequences.isCCW(shell.getCoordinateSequence()) : false;
    coords.put(toJSON(shell, inverse));

    if (poly.getNumInteriorRing() > 0)
    {
        int nRings = poly.getNumInteriorRing();

        for (int j = 0; j < nRings; ++j)
        {
            LineString ring = poly.getInteriorRingN(j);
            inverse = ring.getNumPoints() > 1 ? CoordinateSequences.isCCW(ring.getCoordinateSequence()) : false;
            coords.put(toJSON(ring, inverse));
        }
    }

    return coords;
}
项目:openrouteservice    文件:GeometryJSON.java   
public static JSONArray toJSON(LineString line, boolean inverseSeq)
{
    // "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
    int size = line.getNumPoints();

    JSONArray arrCoords = new JSONArray(size);

    CoordinateSequence seq = line.getCoordinateSequence();
    Coordinate coord = null;

    for (int i = 0; i < size; ++i) 
    {
        coord = seq.getCoordinate(inverseSeq ? size - i - 1: i);

        arrCoords.put(toJSON(coord));
    }

    return arrCoords;
}
项目:openrouteservice    文件:RouteSegmentInfo.java   
public double getLength(DistanceCalc dc) {
    double res = 0;

    if (this.getGeometry() != null) {
        LineString ls = (LineString) this.getGeometry();
        int nPoints = ls.getNumPoints();

        if (nPoints > 1) {
            Coordinate c = ls.getCoordinateN(0);
            double x0 = c.x;
            double y0 = c.y;
            for (int i = 1; i < ls.getNumPoints(); i++) {
                c = ls.getCoordinateN(i);

                res += dc.calcDist(y0, x0, c.y, c.x);
                x0 = c.x;
                y0 = c.y;
            }
        }
    }

    return res;
}
项目:oma-riista-web    文件:PolygonConversionUtil.java   
public static GeoJsonObject javaToGeoJSON(@Nonnull final com.vividsolutions.jts.geom.Geometry geometry) {
    Objects.requireNonNull(geometry);

    if (geometry instanceof com.vividsolutions.jts.geom.MultiPolygon) {
        return javaMultiPolygonToGeoJson(com.vividsolutions.jts.geom.MultiPolygon.class.cast(geometry));
    } else if (geometry instanceof com.vividsolutions.jts.geom.Polygon) {
        return javaPolygonToGeoJson(com.vividsolutions.jts.geom.Polygon.class.cast(geometry));
    } else if (geometry instanceof com.vividsolutions.jts.geom.GeometryCollection) {
        return javaGeometryCollectionToGeoJson(com.vividsolutions.jts.geom.GeometryCollection.class.cast(geometry));
    } else if (geometry instanceof com.vividsolutions.jts.geom.LineString) {
        // TODO: Not required right now...
        return null;
    }

    throw new IllegalArgumentException("Geometry type is not supported: " + geometry.getGeometryType());
}
项目:StreetComplete    文件:GeoJsonReaderTest.java   
public void testGeometryCollection()
{
    Geometry g = read("{\n" +
            "  \"type\": \"GeometryCollection\",\n" +
            "  \"geometries\":\n" +
            "  [\n" +
            "    {\n" +
            "      \"type\": \"Point\",\n" +
            "      \"coordinates\": [5,10]\n" +
            "    },\n" +
            "    {\n" +
            "      \"type\": \"LineString\",\n" +
            "      \"coordinates\": [[5,10],[10,5]]\n" +
            "    }\n" +
            "  ]\n" +
            "}");
    assertTrue(g instanceof GeometryCollection);
    assertEquals(2,g.getNumGeometries());
    assertTrue(g.getGeometryN(0) instanceof Point);
    assertTrue(g.getGeometryN(1) instanceof LineString);
    assertEquals(3,g.getNumPoints());
}
项目:Earth    文件:PointLocator.java   
private int locate(Coordinate p, LineString l) {
    // bounding-box check
    if (!l.getEnvelopeInternal().intersects(p)) {
        return Location.EXTERIOR;
    }

    Coordinate[] pt = l.getCoordinates();
    if (!l.isClosed()) {
        if (p.equals(pt[0])
                || p.equals(pt[pt.length - 1])) {
            return Location.BOUNDARY;
        }
    }
    if (CGAlgorithms.isOnLine(p, pt)) {
        return Location.INTERIOR;
    }
    return Location.EXTERIOR;
}
项目:Earth    文件:RectangleContains.java   
private boolean isContainedInBoundary(Geometry geom) {
    // polygons can never be wholely contained in the boundary
    if (geom instanceof Polygon) {
        return false;
    }
    if (geom instanceof Point) {
        return this.isPointContainedInBoundary((Point) geom);
    }
    if (geom instanceof LineString) {
        return this.isLineStringContainedInBoundary((LineString) geom);
    }

    for (int i = 0; i < geom.getNumGeometries(); i++) {
        Geometry comp = geom.getGeometryN(i);
        if (!this.isContainedInBoundary(comp)) {
            return false;
        }
    }
    return true;
}
项目:geoxygene    文件:AdapterFactory.java   
/**
 * Traduit un type de géométrie JTS {@link Geometry} et renvoie le type de
 * géométrie GeOxygene {@link IGeometry} équivalent. TODO gérer tous les types
 * de géométrie.
 * @param geometryType type de géométrie JTS
 * @return type de géométrie GeOxygene équivalent
 */
public static Class<? extends IGeometry> toGeometryType(Class<?> geometryType) {
  if (LineString.class.equals(geometryType)) {
    return ILineString.class;
  }
  if (MultiLineString.class.equals(geometryType)) {
    return IMultiCurve.class;
  }
  if (Polygon.class.equals(geometryType)) {
    return IPolygon.class;
  }
  if (MultiPolygon.class.equals(geometryType)) {
    return IMultiSurface.class;
  }
  if (Point.class.equals(geometryType)) {
    return IPoint.class;
  }
  if (MultiPoint.class.equals(geometryType)) {
    return IMultiPoint.class;
  }
  return IGeometry.class;
}
项目:sldeditor    文件:CreateInternalDataSource.java   
/**
 * 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);
    AttributeDescriptor attributeDescriptor = b.createAttributeDescriptor(fieldName, fieldType);
    return attributeDescriptor;
}
项目:Earth    文件:PolygonizeGraph.java   
/**
 * Add a {@link LineString} forming an edge of the polygon graph.
 *
 * @param line the line to add
 */
public void addEdge(LineString line) {
    if (line.isEmpty()) {
        return;
    }
    Coordinate[] linePts = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());

    if (linePts.length < 2) {
        return;
    }

    Coordinate startPt = linePts[0];
    Coordinate endPt = linePts[linePts.length - 1];

    Node nStart = this.getNode(startPt);
    Node nEnd = this.getNode(endPt);

    DirectedEdge de0 = new PolygonizeDirectedEdge(nStart, nEnd, linePts[1], true);
    DirectedEdge de1 = new PolygonizeDirectedEdge(nEnd, nStart, linePts[linePts.length - 2], false);
    Edge edge = new PolygonizeEdge(line);
    edge.setDirectedEdges(de0, de1);
    this.add(edge);
}
项目:Earth    文件:ConnectedInteriorTester.java   
private void visitInteriorRing(LineString ring, PlanarGraph graph) {
    Coordinate[] pts = ring.getCoordinates();
    Coordinate pt0 = pts[0];
    /**
     * Find first point in coord list different to initial point.
     * Need special check since the first point may be repeated.
     */
    Coordinate pt1 = findDifferentPoint(pts, pt0);
    Edge e = graph.findEdgeInSameDirection(pt0, pt1);
    DirectedEdge de = (DirectedEdge) graph.findEdgeEnd(e);
    DirectedEdge intDe = null;
    if (de.getLabel().getLocation(0, Position.RIGHT) == Location.INTERIOR) {
        intDe = de;
    } else if (de.getSym().getLabel().getLocation(0, Position.RIGHT) == Location.INTERIOR) {
        intDe = de.getSym();
    }
    Assert.isTrue(intDe != null, "unable to find dirEdge with Interior on RHS");

    this.visitLinkedDirectedEdges(intDe);
}
项目:Earth    文件:WKBWriter.java   
/**
 * Writes a {@link Geometry} to an {@link OutStream}.
 *
 * @param geom the geometry to write
 * @param os the out stream to write to
 * @throws IOException if an I/O error occurs
 */
public void write(Geometry geom, OutStream os) throws IOException {
    if (geom instanceof Point) {
        this.writePoint((Point) geom, os);
    }
    // LinearRings will be written as LineStrings
    else if (geom instanceof LineString) {
        this.writeLineString((LineString) geom, os);
    } else if (geom instanceof Polygon) {
        this.writePolygon((Polygon) geom, os);
    } else if (geom instanceof MultiPoint) {
        this.writeGeometryCollection(WKBConstants.wkbMultiPoint,
                (MultiPoint) geom, os);
    } else if (geom instanceof MultiLineString) {
        this.writeGeometryCollection(WKBConstants.wkbMultiLineString,
                (MultiLineString) geom, os);
    } else if (geom instanceof MultiPolygon) {
        this.writeGeometryCollection(WKBConstants.wkbMultiPolygon,
                (MultiPolygon) geom, os);
    } else if (geom instanceof GeometryCollection) {
        this.writeGeometryCollection(WKBConstants.wkbGeometryCollection,
                (GeometryCollection) geom, os);
    } else {
        Assert.shouldNeverReachHere("Unknown Geometry type");
    }
}
项目:Earth    文件:LineSequencer.java   
private void computeSequence() {
    if (this.isRun) {
        return;
    }
    this.isRun = true;

    List sequences = this.findSequences();
    if (sequences == null) {
        return;
    }

    this.sequencedGeometry = this.buildSequencedGeometry(sequences);
    this.isSequenceable = true;

    int finalLineCount = this.sequencedGeometry.getNumGeometries();
    Assert.isTrue(this.lineCount == finalLineCount, "Lines were missing from result");
    Assert.isTrue(this.sequencedGeometry instanceof LineString
                    || this.sequencedGeometry instanceof MultiLineString,
            "Result is not lineal");
}
项目:Earth    文件:LineMergeGraph.java   
/**
 * Adds an Edge, DirectedEdges, and Nodes for the given LineString representation
 * of an edge.
 * Empty lines or lines with all coordinates equal are not added.
 *
 * @param lineString the linestring to add to the graph
 */
public void addEdge(LineString lineString) {
    if (lineString.isEmpty()) {
        return;
    }

    Coordinate[] coordinates = CoordinateArrays.removeRepeatedPoints(lineString.getCoordinates());

    // don't add lines with all coordinates equal
    if (coordinates.length <= 1) {
        return;
    }

    Coordinate startCoordinate = coordinates[0];
    Coordinate endCoordinate = coordinates[coordinates.length - 1];
    Node startNode = this.getNode(startCoordinate);
    Node endNode = this.getNode(endCoordinate);
    DirectedEdge directedEdge0 = new LineMergeDirectedEdge(startNode, endNode,
            coordinates[1], true);
    DirectedEdge directedEdge1 = new LineMergeDirectedEdge(endNode, startNode,
            coordinates[coordinates.length - 2], false);
    Edge edge = new LineMergeEdge(lineString);
    edge.setDirectedEdges(directedEdge0, directedEdge1);
    this.add(edge);
}
项目:Earth    文件:IsSimpleOp.java   
private boolean computeSimple(Geometry geom) {
    this.nonSimpleLocation = null;
    if (geom.isEmpty()) {
        return true;
    }
    if (geom instanceof LineString) {
        return this.isSimpleLinearGeometry(geom);
    }
    if (geom instanceof MultiLineString) {
        return this.isSimpleLinearGeometry(geom);
    }
    if (geom instanceof MultiPoint) {
        return this.isSimpleMultiPoint((MultiPoint) geom);
    }
    if (geom instanceof Polygonal) {
        return this.isSimplePolygonal(geom);
    }
    if (geom instanceof GeometryCollection) {
        return this.isSimpleGeometryCollection(geom);
    }
    // all other geometry types are simple by definition
    return true;
}