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

项目: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));
    }
}
项目:sumo    文件:JTSUtil.java   
/**
 *
 * @param geom
 * @return
 */
public static Geometry repair (Geometry geom) {
    GeometryFactory factory = geom.getFactory();
    if (geom instanceof MultiPolygon) {
        MultiPolygon mp = (MultiPolygon)geom;
        Polygon[] polys = new Polygon[mp.getNumGeometries()];
        for (int i = 0; i < mp.getNumGeometries(); i += 1) {
            polys[i] = repair((Polygon)mp.getGeometryN(i));
        }
        return factory.createMultiPolygon(polys);
    } else if (geom instanceof Polygon) {
        return repair((Polygon)geom);
    } else if (geom.getGeometryType().equals("GeometryCollection")) {
        GeometryCollection gc = (GeometryCollection)geom;
        Geometry[] geoms = new Geometry[gc.getNumGeometries()];
        for (int i = 0; i < gc.getNumGeometries(); i += 1) {
            geoms[i] = repair(gc.getGeometryN(i));
        }
        Thread.dumpStack();
        return factory.createGeometryCollection(geoms);
    } else {
        return(geom);
    }
}
项目:sumo    文件:JTSUtil.java   
/** */
public static double getSharedAreaRatio (Geometry geom1, Geometry geom2) {
    try {
        return geom1.intersection(geom2).getArea() / geom1.getArea();
    } catch (TopologyException e) {
        // HACK: there appears to be a bug in JTS, but I can't
        // reproduce it consistently. Why should computing the
        // intersection with a MultiPolygon fail when computing
        // the intersection with each of its constituent Polygons
        // succeeds? I have no idea, but it does happen. This
        // seems to fix the problem, though.
        double result = 0.0;
        if (geom2 instanceof GeometryCollection) {
            GeometryCollection gc = (GeometryCollection)geom2;
            for (int j = 0; j < gc.getNumGeometries(); j += 1) {
                result += geom1.intersection(gc.getGeometryN(j)).getArea();
            }
            return result / geom1.getArea();
        } else {
            throw e;
        }
    }
}
项目:openrouteservice    文件:ConcaveBallsIsochroneMapBuilder.java   
private void addIsochrone(IsochroneMap isochroneMap, GeometryCollection points, double isoValue, double maxRadius)
{
    if (points.isEmpty())
        return;

    ConcaveHull ch = new ConcaveHull(points, getConcaveHullTreshold(isoValue), false);
    Geometry geom = ch.getConcaveHull();

    if (geom instanceof GeometryCollection)
    {
        GeometryCollection geomColl = (GeometryCollection)geom;
        if (geomColl.isEmpty())
            return;
    }

    Polygon poly = (Polygon)geom;

    copyConvexHullPoints(poly);

    isochroneMap.addIsochrone(new Isochrone(poly, isoValue, maxRadius));
}
项目:Earth    文件:RepeatedPointTester.java   
public boolean hasRepeatedPoint(Geometry g) {
    if (g.isEmpty()) {
        return false;
    }
    if (g instanceof Point) {
        return false;
    } else if (g instanceof MultiPoint) {
        return false;
    }
    // LineString also handles LinearRings
    else if (g instanceof LineString) {
        return this.hasRepeatedPoint(g.getCoordinates());
    } else if (g instanceof Polygon) {
        return this.hasRepeatedPoint((Polygon) g);
    } else if (g instanceof GeometryCollection) {
        return this.hasRepeatedPoint((GeometryCollection) g);
    } else {
        throw new UnsupportedOperationException(g.getClass().getName());
    }
}
项目: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;
}
项目:Earth    文件:BufferDistanceValidator.java   
private void checkNegativeValid() {
    // Assert: only polygonal inputs can be checked for negative buffers

    // MD - could generalize this to handle GCs too
    if (!(this.input instanceof Polygon
            || this.input instanceof MultiPolygon
            || this.input instanceof GeometryCollection
    )) {
        return;
    }
    Geometry inputCurve = this.getPolygonLines(this.input);
    this.checkMinimumDistance(inputCurve, this.result, this.minValidDistance);
    if (!this.isValid) {
        return;
    }

    this.checkMaximumDistance(inputCurve, this.result, this.maxValidDistance);
}
项目:Earth    文件:OffsetCurveSetBuilder.java   
private void add(Geometry g) {
    if (g.isEmpty()) {
        return;
    }

    if (g instanceof Polygon) {
        this.addPolygon((Polygon) g);
    }
    // LineString also handles LinearRings
    else if (g instanceof LineString) {
        this.addLineString((LineString) g);
    } else if (g instanceof Point) {
        this.addPoint((Point) g);
    } else if (g instanceof MultiPoint) {
        this.addCollection((MultiPoint) g);
    } else if (g instanceof MultiLineString) {
        this.addCollection((MultiLineString) g);
    } else if (g instanceof MultiPolygon) {
        this.addCollection((MultiPolygon) g);
    } else if (g instanceof GeometryCollection) {
        this.addCollection((GeometryCollection) g);
    } else {
        throw new UnsupportedOperationException(g.getClass().getName());
    }
}
项目:Earth    文件:Distance3DOp.java   
private void computeMinDistanceMultiMulti(Geometry g0, Geometry g1, boolean flip) {
    if (g0 instanceof GeometryCollection) {
        int n = g0.getNumGeometries();
        for (int i = 0; i < n; i++) {
            Geometry g = g0.getGeometryN(i);
            this.computeMinDistanceMultiMulti(g, g1, flip);
            if (this.isDone) {
                return;
            }
        }
    } else {
        // handle case of multigeom component being empty
        if (g0.isEmpty()) {
            return;
        }

        // compute planar polygon only once for efficiency
        if (g0 instanceof Polygon) {
            this.computeMinDistanceOneMulti(polyPlane(g0), g1, flip);
        } else {
            this.computeMinDistanceOneMulti(g0, g1, flip);
        }
    }
}
项目:Earth    文件:Distance3DOp.java   
private void computeMinDistanceOneMulti(PlanarPolygon3D poly, Geometry geom, boolean flip) {
    if (geom instanceof GeometryCollection) {
        int n = geom.getNumGeometries();
        for (int i = 0; i < n; i++) {
            Geometry g = geom.getGeometryN(i);
            this.computeMinDistanceOneMulti(poly, g, flip);
            if (this.isDone) {
                return;
            }
        }
    } else {
        if (geom instanceof Point) {
            this.computeMinDistancePolygonPoint(poly, (Point) geom, flip);
            return;
        }
        if (geom instanceof LineString) {
            this.computeMinDistancePolygonLine(poly, (LineString) geom, flip);
            return;
        }
        if (geom instanceof Polygon) {
            this.computeMinDistancePolygonPolygon(poly, (Polygon) geom, flip);
        }
    }
}
项目:Earth    文件:ShapeWriter.java   
/**
 * 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 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 Shape toShape(Geometry geometry) {
    if (geometry.isEmpty()) {
        return new GeneralPath();
    }
    if (geometry instanceof Polygon) {
        return this.toShape((Polygon) geometry);
    }
    if (geometry instanceof LineString) {
        return this.toShape((LineString) geometry);
    }
    if (geometry instanceof MultiLineString) {
        return this.toShape((MultiLineString) geometry);
    }
    if (geometry instanceof Point) {
        return this.toShape((Point) geometry);
    }
    if (geometry instanceof GeometryCollection) {
        return this.toShape((GeometryCollection) geometry);
    }

    throw new IllegalArgumentException(
            "Unrecognized Geometry class: " + geometry.getClass());
}
项目:Earth    文件:SimplePointInAreaLocator.java   
private static boolean containsPoint(Coordinate p, Geometry geom) {
    if (geom instanceof Polygon) {
        return containsPointInPolygon(p, (Polygon) geom);
    } else if (geom instanceof GeometryCollection) {
        Iterator geomi = new GeometryCollectionIterator(geom);
        while (geomi.hasNext()) {
            Geometry g2 = (Geometry) geomi.next();
            if (g2 != geom) {
                if (containsPoint(p, g2)) {
                    return true;
                }
            }
        }
    }
    return false;
}
项目:Earth    文件:CentroidLine.java   
/**
 * Adds the linear components of by a Geometry to the centroid total.
 * If the geometry has no linear components it does not contribute to the centroid,
 *
 * @param geom the geometry to add
 */
public void add(Geometry geom) {
    if (geom instanceof LineString) {
        this.add(geom.getCoordinates());
    } else if (geom instanceof Polygon) {
        Polygon poly = (Polygon) geom;
        // add linear components of a polygon
        this.add(poly.getExteriorRing().getCoordinates());
        for (int i = 0; i < poly.getNumInteriorRing(); i++) {
            this.add(poly.getInteriorRingN(i).getCoordinates());
        }
    } else if (geom instanceof GeometryCollection) {
        GeometryCollection gc = (GeometryCollection) geom;
        for (int i = 0; i < gc.getNumGeometries(); i++) {
            this.add(gc.getGeometryN(i));
        }
    }
}
项目:Earth    文件:GeometryTransformer.java   
protected Geometry transformGeometryCollection(GeometryCollection geom, Geometry parent) {
    List transGeomList = new ArrayList();
    for (int i = 0; i < geom.getNumGeometries(); i++) {
        Geometry transformGeom = this.transform(geom.getGeometryN(i));
        if (transformGeom == null) {
            continue;
        }
        if (this.pruneEmptyGeometry && transformGeom.isEmpty()) {
            continue;
        }
        transGeomList.add(transformGeom);
    }
    if (this.preserveGeometryCollectionType) {
        return this.factory.createGeometryCollection(GeometryFactory.toGeometryArray(transGeomList));
    }
    return this.factory.buildGeometry(transGeomList);
}
项目:Earth    文件:WKTReader.java   
/**
 * Creates a <code>GeometryCollection</code> using the next token in the
 * stream.
 *
 * @param tokenizer tokenizer over a stream of text in Well-known Text
 * format. The next tokens must form a &lt;GeometryCollection Text&gt;.
 * @return a <code>GeometryCollection</code> specified by the
 * next token in the stream
 * @throws ParseException if the coordinates used to create a <code>Polygon</code>
 * shell and holes do not form closed linestrings, or if an unexpected
 * token was encountered
 * @throws IOException if an I/O error occurs
 */
private GeometryCollection readGeometryCollectionText() throws IOException, ParseException {
    String nextToken = this.getNextEmptyOrOpener();
    if (nextToken.equals(EMPTY)) {
        return this.geometryFactory.createGeometryCollection(new Geometry[] {});
    }
    ArrayList geometries = new ArrayList();
    Geometry geometry = this.readGeometryTaggedText();
    geometries.add(geometry);
    nextToken = this.getNextCloserOrComma();
    while (nextToken.equals(COMMA)) {
        geometry = this.readGeometryTaggedText();
        geometries.add(geometry);
        nextToken = this.getNextCloserOrComma();
    }
    Geometry[] array = new Geometry[geometries.size()];
    return this.geometryFactory.createGeometryCollection((Geometry[]) geometries.toArray(array));
}
项目:Earth    文件:GMLWriter.java   
private void write(Geometry geom, Writer writer, int level)
        throws IOException {
    this.isRootTag = true;
    if (geom instanceof Point) {
        this.writePoint((Point) geom, writer, level);
    } else if (geom instanceof LineString) {
        this.writeLineString((LineString) geom, writer, level);
    } else if (geom instanceof Polygon) {
        this.writePolygon((Polygon) geom, writer, level);
    } else if (geom instanceof MultiPoint) {
        this.writeMultiPoint((MultiPoint) geom, writer, level);
    } else if (geom instanceof MultiLineString) {
        this.writeMultiLineString((MultiLineString) geom, writer, level);
    } else if (geom instanceof MultiPolygon) {
        this.writeMultiPolygon((MultiPolygon) geom, writer, level);
    } else if (geom instanceof GeometryCollection) {
        this.writeGeometryCollection((GeometryCollection) geom, writer,
                this.startingIndentIndex);
    } else {
        throw new IllegalArgumentException("Unhandled geometry type: "
                + geom.getGeometryType());
    }
    writer.flush();
}
项目:Earth    文件:GMLWriter.java   
private void writeGeometryCollection(GeometryCollection gc, Writer writer,
                                     int level) throws IOException {
    this.startLine(level, writer);
    this.startGeomTag(GMLConstants.GML_MULTI_GEOMETRY, gc, writer);

    for (int t = 0; t < gc.getNumGeometries(); t++) {
        this.startLine(level + 1, writer);
        this.startGeomTag(GMLConstants.GML_GEOMETRY_MEMBER, null, writer);

        this.write(gc.getGeometryN(t), writer, level + 2);

        this.startLine(level + 1, writer);
        this.endGeomTag(GMLConstants.GML_GEOMETRY_MEMBER, writer);
    }
    this.startLine(level, writer);
    this.endGeomTag(GMLConstants.GML_MULTI_GEOMETRY, writer);
}
项目: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    文件:WKTWriter.java   
/**
 * Converts a <code>GeometryCollection</code> to &lt;GeometryCollectionText&gt;
 * format, then appends it to the writer.
 *
 * @param geometryCollection the <code>GeometryCollection</code> to process
 * @param writer the output writer to append to
 */
private void appendGeometryCollectionText(GeometryCollection geometryCollection, int level,
                                          Writer writer)
        throws IOException {
    if (geometryCollection.isEmpty()) {
        writer.write("EMPTY");
    } else {
        int level2 = level;
        writer.write("(");
        for (int i = 0; i < geometryCollection.getNumGeometries(); i++) {
            if (i > 0) {
                writer.write(", ");
                level2 = level + 1;
            }
            this.appendGeometryTaggedText(geometryCollection.getGeometryN(i), level2, writer);
        }
        writer.write(")");
    }
}
项目:geoxygene    文件:AdapterFactory.java   
/**
 * Traduit un type de géométrie GeOxygene {@link IGeometry} et renvoie le type
 * de géométrie JTS {@link Geometry} équivalent. TODO gérer tous les types de
 * géométrie.
 * @param geometryType type de géométrie GeOxygene
 * @return type de géométrie JTS équivalent
 */
public static Class<? extends Geometry> toJTSGeometryType(
    Class<?> geometryType) {
  if (ILineString.class.isAssignableFrom(geometryType)) {
    return LineString.class;
  }
  if (IMultiCurve.class.isAssignableFrom(geometryType)) {
    return MultiLineString.class;
  }
  if (IPolygon.class.isAssignableFrom(geometryType)) {
    return Polygon.class;
  }
  if (IMultiSurface.class.isAssignableFrom(geometryType)) {
    return MultiPolygon.class;
  }
  if (IPoint.class.isAssignableFrom(geometryType)) {
    return Point.class;
  }
  if (IMultiPoint.class.isAssignableFrom(geometryType)) {
    return MultiPoint.class;
  }
  if (IAggregate.class.isAssignableFrom(geometryType)) {
    return GeometryCollection.class;
  }
  return Geometry.class;
}
项目:gvnix1    文件:EWKTReader.java   
/**
 * Creates a <code>GeometryCollection</code> using the next token in the
 * stream.
 * 
 * @param tokenizer tokenizer over a stream of text in Well-known Text
 *        format. The next tokens must form a &lt;GeometryCollection
 *        Text&gt;.
 * @return a <code>GeometryCollection</code> specified by the next token in
 *         the stream
 * @throws ParseException if the coordinates used to create a
 *         <code>Polygon</code> shell and holes do not form closed
 *         linestrings, or if an unexpected token was encountered
 * @throws IOException if an I/O error occurs
 */
private GeometryCollection readGeometryCollectionText() throws IOException,
        ParseException {

    String nextToken = getNextEmptyOrOpener();
    if (nextToken.equals(EMPTY)) {
        return geometryFactory.createGeometryCollection(new Geometry[] {});
    }
    ArrayList geometries = new ArrayList();
    Geometry geometry = readGeometryTaggedText();
    geometries.add(geometry);
    nextToken = getNextCloserOrComma();
    while (nextToken.equals(COMMA)) {
        geometry = readGeometryTaggedText();
        geometries.add(geometry);
        nextToken = getNextCloserOrComma();
    }
    Geometry[] array = new Geometry[geometries.size()];
    return geometryFactory.createGeometryCollection((Geometry[]) geometries
            .toArray(array));
}
项目:StreetComplete    文件:CountryBoundaries.java   
public CountryBoundaries(GeometryCollection countriesBoundaries)
{
    index = new STRtree();
    geometrySizeCache = new HashMap<>(400);
    geometriesByIsoCodes = new HashMap<>(400);

    for(int i = 0; i < countriesBoundaries.getNumGeometries(); ++i)
    {
        Geometry countryBoundary = countriesBoundaries.getGeometryN(i);

        Map<String,String> props = (Map<String,String>) countryBoundary.getUserData();
        if(props == null) continue;
        if(props.containsKey(ISO3166_1_ALPHA2) || props.containsKey(ISO3166_2))
        {
            insertIntoIndex(countryBoundary);
            insertIntoIsoCodes(countryBoundary);

        }
    }
}
项目:StreetComplete    文件:CountryBoundaries.java   
private void insertIntoIndex(Geometry countryBoundary)
{
    // split multipolygons into its elements and copy the properties to them to make better use
    // of the index data structure. I.e. the United Kingdom would be on the top level of the
    // index since because with all those oversees territories, it spans almost the whole
    // world.
    if(countryBoundary instanceof GeometryCollection)
    {
        GeometryCollection countryBoundaries = (GeometryCollection) countryBoundary;
        for (int j = 0; j < countryBoundaries.getNumGeometries(); j++)
        {
            Geometry countryBoundariesSegment =  countryBoundaries.getGeometryN(j);
            index.insert(countryBoundariesSegment.getEnvelopeInternal(), countryBoundary);
        }
    }
    else
    {
        index.insert(countryBoundary.getEnvelopeInternal(), countryBoundary);
    }
}
项目:StreetComplete    文件:CountryBoundariesGeoJsonTest.java   
public void testCountryBoundariesGeoJson() throws IOException
{
    String geoJson = StreamUtils.readToString(getContext().getAssets().open("countryBoundaries.json"));
    GeometryCollection countriesBoundaries = (GeometryCollection) new GeoJsonReader().read(geoJson);
    for(int i = 0; i < countriesBoundaries.getNumGeometries(); ++i)
    {
        Geometry countryBoundary = countriesBoundaries.getGeometryN(i);
        Map<String,String> props = (Map<String,String>) countryBoundary.getUserData();

        TopologyValidationError err = new IsValidOp(countryBoundary).getValidationError();
        if(err != null) {
            String countryCode = props.get("ISO3166-1:alpha2");
            if(countryCode == null) countryCode = props.get("ISO3166-2");
            fail("" + countryCode + ": " + err.toString());
        }
    }
}
项目: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());
}
项目:geogson    文件:Geom.java   
/**
 * Recursively flattens a list of geometries into it's constituent geometry objects.
 */
public static <T extends Geometry> List<T> flatten(List<Geometry> gl) {
  List<T> flat = new ArrayList<T>();
  LinkedList<Geometry> q = new LinkedList<Geometry>();
  q.addAll(gl);

  while (!q.isEmpty()) {
    Geometry g = q.removeFirst();
    if (g instanceof GeometryCollection) {
      for (Geometry h : iterate((GeometryCollection) g)) {
        q.addLast(h);
      }
    } else {
      flat.add((T) g);
    }
  }
  return flat;
}
项目:eMonocot    文件:LocationTest.java   
/**
 *
 */
@Test
public final void testCompareGeography() throws Exception {
    List<Geometry> list = new ArrayList<Geometry>();
    list.add(Location.EUROPE.getEnvelope());
    list.add(Location.AFRICA.getEnvelope());
    list.add(Location.CHINA.getEnvelope());
    list.add(Location.MACARONESIA.getEnvelope());
    list.add(Location.EASTERN_CANADA.getEnvelope());
    list.add(Location.FRA.getEnvelope());
    list.add(Location.ABT.getEnvelope());
    list.add(Location.GRB.getEnvelope());
    list.add(Location.IRE.getEnvelope());
    list.add(Location.ALG.getEnvelope());

    GeometryCollection geometryCollection = new GeometryCollection(
            list.toArray(new Geometry[list.size()]), new GeometryFactory());

    Coordinate[] envelope = geometryCollection.getEnvelope()
            .getCoordinates();
    for (Coordinate c : envelope) {
        logger.debug(Math.round(c.x) + " " + Math.round(c.y));
    }
}
项目:powop    文件:LocationTest.java   
public final void testCompareGeography() throws Exception {
    List<Geometry> list = new ArrayList<Geometry>();
    list.add(Location.EUROPE.getEnvelope());
    list.add(Location.AFRICA.getEnvelope());
    list.add(Location.CHINA.getEnvelope());
    list.add(Location.MACARONESIA.getEnvelope());
    list.add(Location.EASTERN_CANADA.getEnvelope());
    list.add(Location.FRA.getEnvelope());
    list.add(Location.ABT.getEnvelope());
    list.add(Location.GRB.getEnvelope());
    list.add(Location.IRE.getEnvelope());
    list.add(Location.ALG.getEnvelope());

    GeometryCollection geometryCollection = new GeometryCollection(
            list.toArray(new Geometry[list.size()]), new GeometryFactory());

    Coordinate[] envelope = geometryCollection.getEnvelope().getCoordinates();
    for (Coordinate c : envelope) {
        logger.debug(Math.round(c.x) + " " + Math.round(c.y));
    }
}
项目:Flox    文件:Model.java   
/**
 * Finds an OGC simple feature that contains a point.
 *
 * @param geometry A geometry or geometry collection to search through.
 * @param point The point for which a containing geometry is to be searched.
 * @param f A JTS GeometryFactory
 * @return The found containing geometry or null if none is found.
 */
private Geometry findContainingGeometry(Geometry geometry,
        Point point, GeometryFactory f) {
    if (geometry == null) {
        return null;
    }

    Coordinate coordinate = new Coordinate(point.x, point.y);
    com.vividsolutions.jts.geom.Point p = f.createPoint(coordinate);

    Iterator geomi = new GeometryCollectionIterator(geometry);
    while (geomi.hasNext()) {
        Geometry g = (Geometry) geomi.next();
        if (g instanceof GeometryCollection == false && p.within(g)) {
            return g;
        }
    }

    return null;
}
项目:Flox    文件:MainWindow.java   
private void selectEndClipAreaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectEndClipAreaButtonActionPerformed
    try {
        // ask for import file
        String inFilePath = FileUtils.askFile(this, "Shapefile", true);
        if (inFilePath == null) {
            // user canceled
            return;
        }

        // read shapefile
        GeometryCollection collection = new ShapeGeometryImporter().read(inFilePath);
        if (collection == null) {
            ErrorDialog.showErrorDialog("The selected file is not a shapefile.", "Flox Error");
            return;
        }

        model.setClipAreas(collection);
        updateClippingGUI();
    } catch (IOException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        ErrorDialog.showErrorDialog("An error occured.", "Flox Error", ex, null);
    } finally {
        writeSymbolGUI();
    }
}
项目:gama    文件:GamaShape.java   
@Override
public void setInnerGeometry(final Geometry geom) {
    if (geom == null) {
        geometry = null;
        return;
    }
    if (geom.isEmpty()) {
        // See Issue 725
        return;
    }
    if (geom instanceof GeometryCollection && geom.getNumGeometries() == 1) {
        geometry = geom.getGeometryN(0);
    } else {
        geometry = geom;
    }
}
项目:gama    文件:Projection.java   
@Override
public Geometry transform(final Geometry g) {
    // Remove uselessly complicated multigeometries
    if (g instanceof GeometryCollection && g.getNumGeometries() == 1) { return transform(g.getGeometryN(0)); }
    Geometry geom = GeometryUtils.GEOMETRY_FACTORY.createGeometry(g);
    if (transformer != null) {
        try {
            geom = transformer.transform(geom);
        } catch (final TransformException e) {
            e.printStackTrace();
        }
    }
    translate(geom);
    convertUnit(geom);
    return geom;
}
项目:gama    文件:GeometryUtils.java   
public static IList<IShape> triangulation(final IScope scope, final IList<IShape> lines) {
    final IList<IShape> geoms = GamaListFactory.create(Types.GEOMETRY);
    final ConformingDelaunayTriangulationBuilder dtb = new ConformingDelaunayTriangulationBuilder();

    final Geometry points = GamaGeometryType.geometriesToGeometry(scope, lines).getInnerGeometry();
    final double sizeTol = FastMath.sqrt(points.getEnvelope().getArea()) / 100.0;

    dtb.setSites(points);
    dtb.setConstraints(points);
    dtb.setTolerance(sizeTol);
    final GeometryCollection tri = (GeometryCollection) dtb.getTriangles(GEOMETRY_FACTORY);
    final int nb = tri.getNumGeometries();
    for (int i = 0; i < nb; i++) {
        final Geometry gg = tri.getGeometryN(i);
        geoms.add(new GamaShape(gg));
    }
    return geoms;
}
项目:gama    文件:Spatial.java   
@operator (
        value = { "points_on" },
        type = IType.LIST,
        content_type = IType.POINT,
        category = { IOperatorCategory.SPATIAL, IOperatorCategory.POINT },
        concept = { IConcept.GEOMETRY, IConcept.SPATIAL_COMPUTATION, IConcept.SPATIAL_RELATION,
                IConcept.POINT })
@doc (
        value = "A list of points of the operand-geometry distant from each other to the float right-operand .",
        examples = { @example (
                value = " square(5) points_on(2)",
                equals = "a list of points belonging to the exterior ring of the square distant from each other of 2.",
                test = false) },
        see = { "closest_points_with", "farthest_point_to", "points_at" })
public static IList points_on(final IShape geom, final Double distance) {
    final IList<GamaPoint> locs = GamaListFactory.create(Types.POINT);
    if (geom.getInnerGeometry() instanceof GeometryCollection) {
        for (int i = 0; i < geom.getInnerGeometry().getNumGeometries(); i++) {
            locs.addAll(GeometryUtils.locsOnGeometry(geom.getInnerGeometry().getGeometryN(i), distance));
        }
    } else {
        locs.addAll(GeometryUtils.locsOnGeometry(geom.getInnerGeometry(), distance));
    }
    return locs;
}
项目:gama    文件:Spatial.java   
@operator (
        value = { "points_along" },
        type = IType.LIST,
        content_type = IType.POINT,
        category = { IOperatorCategory.SPATIAL, IOperatorCategory.POINT },
        concept = { IConcept.GEOMETRY, IConcept.SPATIAL_COMPUTATION, IConcept.SPATIAL_RELATION,
                IConcept.POINT })
@doc (
        value = "A list of points along the operand-geometry given its location in terms of rate of distance from the starting points of the geometry.",
        examples = { @example (
                value = " line([{10,10},{80,80}]) points_along ([0.3, 0.5, 0.9])",
                equals = "the list of following points: [{31.0,31.0,0.0},{45.0,45.0,0.0},{73.0,73.0,0.0}]",
                test = false) },
        see = { "closest_points_with", "farthest_point_to", "points_at", "points_on" })
public static IList points_along(final IShape geom, final IList<Double> rates) {
    final IList<GamaPoint> locs = GamaListFactory.create(Types.POINT);
    if (geom.getInnerGeometry() instanceof GeometryCollection) {
        for (int i = 0; i < geom.getInnerGeometry().getNumGeometries(); i++) {
            locs.addAll(GeometryUtils.locsAlongGeometry(geom.getInnerGeometry().getGeometryN(i), rates));
        }
    } else {
        locs.addAll(GeometryUtils.locsAlongGeometry(geom.getInnerGeometry(), rates));
    }
    return locs;
}
项目:elasticgeo    文件:RandomGeometryBuilder.java   
public GeometryCollection createRandomGeometryCollection() {
    Geometry[] geometries = new Geometry[numGeometries];
    for (int i=0; i<numGeometries; i++) {
        switch (random.nextInt(3)) {
        case 0:
            geometries[i] = createRandomPoint();
            break;
        case 1:
            geometries[i] = createRandomLineString();
            break;
        default:
            geometries[i] = createRandomPolygon();
        }
    }
    return geometryFactory.createGeometryCollection(geometries);
}
项目:jts    文件:SameStructureTester.java   
public static boolean isSameStructure(Geometry g1, Geometry g2)
{
  if (g1.getClass() != g2.getClass())
    return false;
  if (g1 instanceof GeometryCollection)
    return isSameStructureCollection((GeometryCollection) g1, (GeometryCollection) g2);
  else if (g1 instanceof Polygon)
    return isSameStructurePolygon((Polygon) g1, (Polygon) g2);
  else if (g1 instanceof LineString)
    return isSameStructureLineString((LineString) g1, (LineString) g2);
  else if (g1 instanceof Point)
    return isSameStructurePoint((Point) g1, (Point) g2);

  Assert.shouldNeverReachHere(
      "Unsupported Geometry class: " + g1.getClass().getName());
  return false;
}
项目:modelingcommons    文件:JTSUtils.java   
/** */
public static Geometry repair (Geometry geom) {
    GeometryFactory factory = geom.getFactory();
    if (geom instanceof MultiPolygon) {
        MultiPolygon mp = (MultiPolygon)geom;
        Polygon[] polys = new Polygon[mp.getNumGeometries()];
        for (int i = 0; i < mp.getNumGeometries(); i += 1) {
            polys[i] = repair((Polygon)mp.getGeometryN(i));
        }
        return factory.createMultiPolygon(polys);
    } else if (geom instanceof Polygon) {
        return repair((Polygon)geom);
    } else if (geom.getGeometryType().equals("GeometryCollection")) {
        GeometryCollection gc = (GeometryCollection)geom;
        Geometry[] geoms = new Geometry[gc.getNumGeometries()];
        for (int i = 0; i < gc.getNumGeometries(); i += 1) {
            geoms[i] = repair(gc.getGeometryN(i));
        }
        Thread.dumpStack();
        return factory.createGeometryCollection(geoms);
    } else {
        return(geom);
    }
}
项目:modelingcommons    文件:JTSUtils.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));
    }
}
项目:modelingcommons    文件:JTSUtils.java   
/** */
public static double getSharedAreaRatio (Geometry geom1, Geometry geom2) {
    try {
        return geom1.intersection(geom2).getArea() / geom1.getArea();
    } catch (TopologyException e) {
        // HACK: there appears to be a bug in JTS, but I can't
        // reproduce it consistently. Why should computing the
        // intersection with a MultiPolygon fail when computing
        // the intersection with each of its constituent Polygons
        // succeeds? I have no idea, but it does happen. This 
        // seems to fix the problem, though.
        double result = 0.0;
        if (geom2 instanceof GeometryCollection) {
            GeometryCollection gc = (GeometryCollection)geom2;
            for (int j = 0; j < gc.getNumGeometries(); j += 1) {
                result += geom1.intersection(gc.getGeometryN(j)).getArea();
            }
            return result / geom1.getArea();
        } else {
            throw e;
        }
    }
}