/** */
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));
}
}
java类com.vividsolutions.jts.geom.LineString的实例源码
JTSUtil.java 文件源码
项目:sumo
阅读 30
收藏 0
点赞 0
评论 0
GeoJSONShapeParserTests.java 文件源码
项目:elasticsearch_my
阅读 22
收藏 0
点赞 0
评论 0
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);
}
LongLineSplitter.java 文件源码
项目:fpm
阅读 27
收藏 0
点赞 0
评论 0
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");
}
LongLineSplitterTest.java 文件源码
项目:fpm
阅读 24
收藏 0
点赞 0
评论 0
@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)));
}
ClipProcess.java 文件源码
项目:sumo
阅读 27
收藏 0
点赞 0
评论 0
@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);
}
}
}
LineStringBuilder.java 文件源码
项目:elasticsearch_my
阅读 25
收藏 0
点赞 0
评论 0
@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);
}
ElasticsearchGeoAssertions.java 文件源码
项目:elasticsearch_my
阅读 25
收藏 0
点赞 0
评论 0
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() + "]");
}
}
WayGraphModelFactory.java 文件源码
项目:graphium
阅读 19
收藏 0
点赞 0
评论 0
@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;
}
WayGraphModelFactory.java 文件源码
项目:graphium
阅读 27
收藏 0
点赞 0
评论 0
@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;
}
WayGraphModelFactory.java 文件源码
项目:graphium
阅读 24
收藏 0
点赞 0
评论 0
@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);
}
WayGraphModelFactory.java 文件源码
项目:graphium
阅读 23
收藏 0
点赞 0
评论 0
@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);
}
BaseWaySegment.java 文件源码
项目:graphium
阅读 18
收藏 0
点赞 0
评论 0
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;
}
WaySegment.java 文件源码
项目:graphium
阅读 26
收藏 0
点赞 0
评论 0
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;
}
BaseWaySegmentDTOImpl.java 文件源码
项目:graphium
阅读 18
收藏 0
点赞 0
评论 0
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;
}
WaySegmentDTOImpl.java 文件源码
项目:graphium
阅读 17
收藏 0
点赞 0
评论 0
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;
}
LongLineSplitterTest.java 文件源码
项目:fpm
阅读 33
收藏 0
点赞 0
评论 0
@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));
}
LongLineSplitterTest.java 文件源码
项目:fpm
阅读 26
收藏 0
点赞 0
评论 0
@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)));
}
BaseLineStringBuilder.java 文件源码
项目:Elasticsearch
阅读 28
收藏 0
点赞 0
评论 0
@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);
}
JtsAdapter.java 文件源码
项目:vt-support
阅读 30
收藏 0
点赞 0
评论 0
/**
* 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;
}
JtsGeomStats.java 文件源码
项目:vt-support
阅读 23
收藏 0
点赞 0
评论 0
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;
}
JtsGeomStats.java 文件源码
项目:vt-support
阅读 25
收藏 0
点赞 0
评论 0
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;
}
RealTrafficDataProvider.java 文件源码
项目:openrouteservice
阅读 28
收藏 0
点赞 0
评论 0
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;
}
JTS.java 文件源码
项目:openrouteservice
阅读 30
收藏 0
点赞 0
评论 0
/**
* 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());
}
JsonLocationsRequestParser.java 文件源码
项目:openrouteservice
阅读 28
收藏 0
点赞 0
评论 0
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()));
}
}
GeometryJSON.java 文件源码
项目:openrouteservice
阅读 28
收藏 0
点赞 0
评论 0
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());
}
}
GeometryJSON.java 文件源码
项目:openrouteservice
阅读 29
收藏 0
点赞 0
评论 0
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;
}
GeometryJSON.java 文件源码
项目:openrouteservice
阅读 30
收藏 0
点赞 0
评论 0
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;
}
RouteSegmentInfo.java 文件源码
项目:openrouteservice
阅读 24
收藏 0
点赞 0
评论 0
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;
}
PolygonConversionUtil.java 文件源码
项目:oma-riista-web
阅读 17
收藏 0
点赞 0
评论 0
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());
}
GeoJsonReaderTest.java 文件源码
项目:StreetComplete
阅读 21
收藏 0
点赞 0
评论 0
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());
}