本文整理汇总了Java中com.vividsolutions.jts.operation.linemerge.LineMerger.add方法的典型用法代码示例。如果您正苦于以下问题:Java LineMerger.add方法的具体用法?Java LineMerger.add怎么用?Java LineMerger.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.operation.linemerge.LineMerger
的用法示例。
在下文中一共展示了LineMerger.add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.vividsolutions.jts.operation.linemerge.LineMerger; //导入方法依赖的package包/类
void run() throws Exception {
Collection lineStrings = getData();
LineMerger lineMerger = new LineMerger();
lineMerger.add(lineStrings);
Collection mergedLineStrings = lineMerger.getMergedLineStrings();
System.out.println("Lines formed (" + mergedLineStrings.size() + "):");
System.out.println(mergedLineStrings);
}
示例2: dissolveLines
import com.vividsolutions.jts.operation.linemerge.LineMerger; //导入方法依赖的package包/类
private Geometry dissolveLines(Geometry lines) {
Geometry dissolved = lines.union();
LineMerger merger = new LineMerger();
merger.add(dissolved);
Collection mergedColl = merger.getMergedLineStrings();
Geometry merged = lines.getFactory().buildGeometry(mergedColl);
return merged;
}
示例3: mergeLinestrings
import com.vividsolutions.jts.operation.linemerge.LineMerger; //导入方法依赖的package包/类
/**
* Tries to merge multilines when they are snapped properly.
*
* @param multiLines the lines to merge.
* @return the list of lines, ideally containing a single line,merged.
*/
@SuppressWarnings("unchecked")
public static List<LineString> mergeLinestrings( List<LineString> multiLines ) {
LineMerger lineMerger = new LineMerger();
for( int i = 0; i < multiLines.size(); i++ ) {
Geometry line = multiLines.get(i);
lineMerger.add(line);
}
Collection<Geometry> merged = lineMerger.getMergedLineStrings();
List<LineString> mergedList = new ArrayList<>();
for( Geometry geom : merged ) {
mergedList.add((LineString) geom);
}
return mergedList;
}
示例4: lineMerge
import com.vividsolutions.jts.operation.linemerge.LineMerger; //导入方法依赖的package包/类
public static Geometry lineMerge(Geometry g)
{
LineMerger merger = new LineMerger();
merger.add(g);
Collection lines = merger.getMergedLineStrings();
return g.getFactory().buildGeometry(lines);
}
示例5: processGeometries
import com.vividsolutions.jts.operation.linemerge.LineMerger; //导入方法依赖的package包/类
private static List<Geometry> processGeometries(List<Geometry> geoms, GeometryFactory geomFactory)
{
List<Geometry> result = new ArrayList<Geometry>();
if (geoms.size() > 1)
{
// Create one LineString from a set of LineStrings.
LineMerger lineMerger = new LineMerger();
lineMerger.add(geoms);
LineSequencer lineSeq = new LineSequencer();
lineSeq.add(lineMerger.getMergedLineStrings());
if (lineSeq.isSequenceable())
{
Geometry geomSeq = lineSeq.getSequencedLineStrings();
if (geomSeq instanceof LineString)
{
result.add(geomSeq);
}
else
{
MultiLineString mls = (MultiLineString)geomSeq;
List<Geometry> geoms2 = new ArrayList<Geometry>();
for(int gi = 0; gi < mls.getNumGeometries(); gi++)
geoms2.add(mls.getGeometryN(gi));
if (canMergeGeometries(geoms2))
result.add(mergeGeometries(geoms2, geomFactory));
else
result.addAll(geoms2);
}
}
else
{
if (canMergeGeometries(geoms))
result.add(mergeGeometries(geoms, geomFactory));
else
result.addAll(geoms);
}
}
else
{
result.add(geoms.get(0));
}
return result;
}
示例6: merge
import com.vividsolutions.jts.operation.linemerge.LineMerger; //导入方法依赖的package包/类
private Collection merge(Collection linestrings) {
LineMerger merger = new LineMerger();
merger.add(linestrings);
return merger.getMergedLineStrings();
}
示例7: cutOnPoles
import com.vividsolutions.jts.operation.linemerge.LineMerger; //导入方法依赖的package包/类
/**
* Cut given polygon on poles (89 and -89)
*/
private static String cutOnPoles(String polygonWKT) throws Exception
{
JtsSpatialContextFactory noCheckFactory = new JtsSpatialContextFactory();
noCheckFactory.datelineRule = DatelineRule.none;
noCheckFactory.validationRule = ValidationRule.none;
JtsSpatialContext noCheckContext = noCheckFactory.newSpatialContext();
JtsWKTReaderShapeParser noCheckParser =
new JtsWKTReaderShapeParser(noCheckContext, noCheckFactory);
JtsGeometry polygon = (JtsGeometry) noCheckParser.parse(polygonWKT);
JtsGeometry northPole =
(JtsGeometry) noCheckParser.parse("LINESTRING(180 89, 0 89, -180 89)");
JtsGeometry southPole =
(JtsGeometry) noCheckParser.parse("LINESTRING(180 -89, 0 -89, -180 -89)");
LineMerger lm = new LineMerger();
lm.add(polygon.getGeom());
lm.add(northPole.getGeom());
lm.add(southPole.getGeom());
Geometry geometry = UnaryUnionOp.union(lm.getMergedLineStrings());
Polygonizer polygonizer = new Polygonizer();
polygonizer.add(geometry);
List<Polygon> foundPolygons = (List<Polygon>) polygonizer.getPolygons();
List<Polygon> filteredPolygons = new ArrayList<>();
for (Polygon p: foundPolygons)
{
// removing polygons over the poles
if (p.getCentroid().getCoordinate().y < 89 && p.getCentroid().getCoordinate().y > -89)
{
filteredPolygons.add(p);
}
}
Geometry res = null;
if (!filteredPolygons.isEmpty())
{
res = filteredPolygons.get(0);
}
if (filteredPolygons.size() > 1)
{
// Should not happen...
LOGGER.error("A Multipolygon was found, instead of a single polygon. Only the first one is retained.");
}
WKTWriter wkw = new WKTWriter();
return wkw.write(res);
}