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

项目: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);
    }
}
项目: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() + "]");
    }
}
项目: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    文件:MvtReaderTest.java   
@Test
public void testNegExtPolyRings() {
  try {
    // Single MultiPolygon with two triangles that have negative area from shoelace formula
    // Support for 'V1' MVTs.
    final JtsMvt mvt = loadMvt(
        "src/test/resources/mapbox/vector_tile_js/multi_poly_neg_exters.mvt",
        MvtReader.RING_CLASSIFIER_V1);
    final List<Geometry> geoms = getAllGeometries(mvt);

    assertEquals(1, geoms.size());
    assertTrue(geoms.get(0) instanceof MultiPolygon);
  } catch (IOException exception) {
    fail(exception.getMessage());
  }
}
项目: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    文件: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());
    }
}
项目:embedding    文件:CommunityAreas.java   
public CommunityAreas() {
    communities = new HashMap<>();
    try {
        File f = new File(shapeFilePath);
        ShapefileDataStore shapefile = new ShapefileDataStore(f.toURI().toURL());

        SimpleFeatureIterator features = shapefile.getFeatureSource().getFeatures().features();
        SimpleFeature shp;
        while (features.hasNext()) {
            shp = features.next();
            int id = Integer.parseInt((String) shp.getAttribute("AREA_NUMBE"));
            String name = (String) shp.getAttribute("COMMUNITY");
            MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
            CommunityArea ca = new CommunityArea(id, name, boundary);
            communities.put(id, ca);
        }
        features.close();
        shapefile.dispose();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:embedding    文件:Tracts.java   
public Tracts() {
    tracts = new HashMap<>();
    try {
        SimpleFeatureIterator features = getShapeFileFeatures();
        SimpleFeature shp;
        while (features.hasNext()) {
            shp = features.next();
            int id = Integer.parseInt((String) shp.getAttribute("tractce10"));
            MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
            Tract t = new Tract(id, boundary);
            tracts.put(id, t);
        }
        features.close();
        shapefile.dispose();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:embedding    文件:TractsTest.java   
public void testAllShapesArePolygon() {
    try {
        SimpleFeatureIterator features = Tracts.getShapeFileFeatures();
        SimpleFeature shp = features.next();

        int fieldSize = shp.getType().getTypes().size();
        assertEquals(fieldSize, 10);
        assertEquals(shp.getType().getType(3).getName().getLocalPart(), "tractce10");
        assertEquals(shp.getType().getType(0).getName().getLocalPart(), "MultiPolygon");
        for (int i = 0; i < fieldSize; i++){
            System.out.println(shp.getType().getType(i).getName().getLocalPart());
        }

        int cnt = 1;
        while (features.hasNext()) {
            shp = features.next();
            MultiPolygon g = (MultiPolygon) shp.getDefaultGeometry();
            cnt ++;
        }
        assertEquals(cnt, 801);
        features.close();
        Tracts.shapefile.dispose();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:embedding    文件:TractsTest.java   
public void testTractCentroidDistance() {
    GeometryFactory gf = new GeometryFactory();

    Coordinate[] coords1 = new Coordinate[]{
            new Coordinate(0, 0), new Coordinate(2, 0), new Coordinate(2,2),
            new Coordinate(0, 2), new Coordinate(0, 0)
    };
    MultiPolygon mp1 = gf.createMultiPolygon(new Polygon[] {gf.createPolygon(coords1)});
    Tract t1 = new Tract(1, mp1);
    assertEquals(t1.getCentroid().getX(), 1.0);
    assertEquals(t1.getCentroid().getY(), 1.0);

    Coordinate[] coords2 = new Coordinate[]{
            new Coordinate(0, 10), new Coordinate(2, 10), new Coordinate(2,12),
            new Coordinate(0, 12), new Coordinate(0, 10)
    };
    MultiPolygon mp2 = gf.createMultiPolygon(new Polygon[] {gf.createPolygon(coords2)});
    Tract t2 = new Tract(2, mp2);
    assertEquals(t2.getCentroid().getX(), 1.0);
    assertEquals(t2.getCentroid().getY(), 11.0);

    assertEquals(t1.distanceTo(t2), 10.0);
}
项目:strata-tutorials    文件:GeoInfo.java   
public static GeoInfo fromSimpleFeature(SimpleFeature feature) {
    GeoInfo that = new GeoInfo();
    for (Property p: feature.getProperties()) {
        if (p.getName().toString().equals("NAME"))
            that.name = p.getValue().toString();
        if (p.getName().toString().equals("STATE"))
            that.state = p.getValue().toString();

        if (p.getName().toString().equals("COUNTY"))
            that.county = p.getValue().toString();

        if (p.getName().toString().equals("CITY"))
            that.city = p.getValue().toString();
    }

    that.multiPolygon = (MultiPolygon) feature.getDefaultGeometry();
    return that;
}
项目:Earth    文件:IsValidOp.java   
/**
 * Tests that no element polygon is wholly in the interior of another element polygon.
 * <p>
 * Preconditions:
 * <ul>
 * <li>shells do not partially overlap
 * <li>shells do not touch along an edge
 * <li>no duplicate rings exist
 * </ul>
 * This routine relies on the fact that while polygon shells may touch at one or
 * more vertices, they cannot touch at ALL vertices.
 */
private void checkShellsNotNested(MultiPolygon mp, GeometryGraph graph) {
    for (int i = 0; i < mp.getNumGeometries(); i++) {
        Polygon p = (Polygon) mp.getGeometryN(i);
        LinearRing shell = (LinearRing) p.getExteriorRing();
        for (int j = 0; j < mp.getNumGeometries(); j++) {
            if (i == j) {
                continue;
            }
            Polygon p2 = (Polygon) mp.getGeometryN(j);
            this.checkShellNotNested(shell, p2, graph);
            if (this.validErr != null) {
                return;
            }
        }
    }
}
项目: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    文件:GeometryGraph.java   
/**
     * Compute self-nodes, taking advantage of the Geometry type to
     * minimize the number of intersection tests.  (E.g. rings are
     * not tested for self-intersection, since they are assumed to be valid).
     *
     * @param li the LineIntersector to use
     * @param computeRingSelfNodes if <false>, intersection checks are optimized to not test rings for self-intersection
     * @return the SegmentIntersector used, containing information about the intersections found
     */
    public SegmentIntersector computeSelfNodes(LineIntersector li, boolean computeRingSelfNodes) {
        SegmentIntersector si = new SegmentIntersector(li, true, false);
        EdgeSetIntersector esi = this.createEdgeSetIntersector();
        // optimized test for Polygons and Rings
        if (!computeRingSelfNodes
                && (this.parentGeom instanceof LinearRing
                || this.parentGeom instanceof Polygon
                || this.parentGeom instanceof MultiPolygon)) {
            esi.computeIntersections(this.edges, si, false);
        } else {
            esi.computeIntersections(this.edges, si, true);
        }
//System.out.println("SegmentIntersector # tests = " + si.numTests);
        this.addSelfIntersectionNodes(this.argIndex);
        return si;
    }
项目:Earth    文件:WKTReader.java   
/**
 * Creates a <code>MultiPolygon</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;MultiPolygon Text&gt;.
 * @return a <code>MultiPolygon</code> specified by the next
 * token in the stream, or if if the coordinates used to create the
 * <code>Polygon</code> shells and holes do not form closed linestrings.
 * @throws IOException if an I/O error occurs
 * @throws ParseException if an unexpected token was encountered
 */
private MultiPolygon readMultiPolygonText() throws IOException, ParseException {
    String nextToken = this.getNextEmptyOrOpener();
    if (nextToken.equals(EMPTY)) {
        return this.geometryFactory.createMultiPolygon(new Polygon[] {});
    }
    ArrayList polygons = new ArrayList();
    Polygon polygon = this.readPolygonText();
    polygons.add(polygon);
    nextToken = this.getNextCloserOrComma();
    while (nextToken.equals(COMMA)) {
        polygon = this.readPolygonText();
        polygons.add(polygon);
        nextToken = this.getNextCloserOrComma();
    }
    Polygon[] array = new Polygon[polygons.size()];
    return this.geometryFactory.createMultiPolygon((Polygon[]) polygons.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 writeMultiPolygon(MultiPolygon mp, Writer writer, int level)
        throws IOException {
    this.startLine(level, writer);
    this.startGeomTag(GMLConstants.GML_MULTI_POLYGON, mp, writer);

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

        this.writePolygon((Polygon) mp.getGeometryN(t), writer, level + 2);

        this.startLine(level + 1, writer);
        this.endGeomTag(GMLConstants.GML_POLYGON_MEMBER, writer);
    }
    this.startLine(level, writer);
    this.endGeomTag(GMLConstants.GML_MULTI_POLYGON, 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>MultiPolygon</code> to &lt;MultiPolygon Text&gt; format,
 * then appends it to the writer.
 *
 * @param multiPolygon the <code>MultiPolygon</code> to process
 * @param writer the output writer to append to
 */
private void appendMultiPolygonText(MultiPolygon multiPolygon, int level, Writer writer)
        throws IOException {
    if (multiPolygon.isEmpty()) {
        writer.write("EMPTY");
    } else {
        int level2 = level;
        boolean doIndent = false;
        writer.write("(");
        for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
            if (i > 0) {
                writer.write(", ");
                level2 = level + 1;
                doIndent = true;
            }
            this.appendPolygonText((Polygon) multiPolygon.getGeometryN(i), level2, doIndent, writer);
        }
        writer.write(")");
    }
}
项目:geoxygene    文件:DTMArea.java   
public double calcul3DArea(IGeometry geom) throws Exception {
  double area = -1;
  if (geom instanceof GM_OrientableSurface || geom instanceof GM_MultiSurface<?>) {
    // On la convertit en JTS
    Geometry geomJTS = JtsGeOxygene.makeJtsGeom(geom);
    if (geomJTS instanceof Polygon) {
      // Polygon on applique tout de suite
      area = area + this.calcul3DArea((Polygon) geomJTS);
    } else
      if (geomJTS instanceof MultiPolygon) {
        // MultiPolygon on l'applique par morceaux
        MultiPolygon multiP = (MultiPolygon) geomJTS;
        int nGeom = multiP.getNumGeometries();
        for (int j = 0; j < nGeom; j++) {
          area = area + this.calcul3DArea((Polygon) multiP.getGeometryN(j));
        }
      } else {
        // Type de géométrie non reconnue
        logger.warn("Geomtrie non reconnue" + geomJTS.getClass().toString());
      }
  } else {
    // Type de géométrie non reconnue
    logger.warn("Geomtrie non reconnue" + geom.getClass().toString());
  }
  return area;
}
项目: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;
}
项目: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;
}
项目:sldeditor    文件:AllowedAttributeTypes.java   
/**
 * Initialise.
 */
private static void initialise()
{
    List<Class<?> > doubleList = new ArrayList<Class<?> >(Arrays.asList(Integer.class, Long.class, Double.class, Float.class));
    List<Class<?> > integerList = new ArrayList<Class<?> >(Arrays.asList(Integer.class, Long.class));
    List<Class<?> > stringList = new ArrayList<Class<?> >(Arrays.asList(String.class));
    List<Class<?> > geometryList = new ArrayList<Class<?> >(Arrays.asList(Point.class, LineString.class, Polygon.class, MultiPolygon.class, MultiPoint.class, MultiLineString.class));

    allowedClassTypeMap.put(String.class, stringList);
    allowedClassTypeMap.put(Double.class, doubleList);
    allowedClassTypeMap.put(Float.class, doubleList);
    allowedClassTypeMap.put(Integer.class, integerList);
    allowedClassTypeMap.put(Long.class, integerList);
    allowedClassTypeMap.put(Geometry.class, geometryList);

    List<Class<?> > objectList = new ArrayList<Class<?>>();
    objectList.addAll(doubleList);
    objectList.addAll(integerList);
    objectList.addAll(stringList);
    objectList.addAll(geometryList);
    allowedClassTypeMap.put(Object.class, objectList);
}
项目: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;
}
项目:sldeditor    文件:ExtractAttributes.java   
/**
 * (non-Javadoc)
 * 
 * @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.PolygonSymbolizer)
 */
public void visit(PolygonSymbolizer poly) {
    PolygonSymbolizer copy = sf.createPolygonSymbolizer();
    copy.setFill(copy(poly.getFill()));

    copy.setGeometry(copy(MultiPolygon.class, poly.getGeometry()));

    copy.setUnitOfMeasure(poly.getUnitOfMeasure());
    copy.setStroke(copy(poly.getStroke()));
    copy.getOptions().putAll(poly.getOptions());

    if (STRICT && !copy.equals(poly)) {
        throw new IllegalStateException(
                "Was unable to duplicate provided PolygonSymbolizer:" + poly);
    }
    pages.push(copy);
}
项目:gvnix1    文件:EWKTReader.java   
/**
 * Creates a <code>MultiPolygon</code> using the next token in the stream.
 * 
 * @param hasM
 * @param tokenizer tokenizer over a stream of text in Well-known Text
 *        format. The next tokens must form a &lt;MultiPolygon Text&gt;.
 * @return a <code>MultiPolygon</code> specified by the next token in the
 *         stream, or if if the coordinates used to create the
 *         <code>Polygon</code> shells and holes do not form closed
 *         linestrings.
 * @throws IOException if an I/O error occurs
 * @throws ParseException if an unexpected token was encountered
 */
private MultiPolygon readMultiPolygonText() throws IOException,
        ParseException {

    // MultiPolygonM is not supported
    setHasM(false);

    String nextToken = getNextEmptyOrOpener();
    if (nextToken.equals(EMPTY)) {
        return geometryFactory.createMultiPolygon(new Polygon[] {});
    }
    ArrayList polygons = new ArrayList();
    Polygon polygon = readPolygonText();
    polygons.add(polygon);
    nextToken = getNextCloserOrComma();
    while (nextToken.equals(COMMA)) {
        polygon = readPolygonText();
        polygons.add(polygon);
        nextToken = getNextCloserOrComma();
    }
    Polygon[] array = new Polygon[polygons.size()];
    return geometryFactory.createMultiPolygon((Polygon[]) polygons
            .toArray(array));
}
项目:StreetComplete    文件:GeoJsonReader.java   
private MultiPolygon createMultiPolygon(JSONArray coords) throws JSONException
{
    ArrayList<Polygon> polygons = new ArrayList<>(coords.length());
    for (int i = 0; i < coords.length(); i++)
    {
        polygons.add(createPolygon(coords.getJSONArray(i)));
    }

    /* JTS MultiPolygon imposes a restriction on the contained Polygons that a GeoJson
     * MultiPolygon does not impose. From the JTS documentation:
     * "As per the OGC SFS specification, the Polygons in a MultiPolygon may not overlap, and
     *  may only touch at single points. This allows the topological point-set semantics to be
     *  well-defined."*/
    mergePolygons(polygons);

    return factory.createMultiPolygon(polygons.toArray(new Polygon[]{}));
}
项目:dhis2-core    文件:GeoToolsPrimitiveFromJsonFactory.java   
/**
 * Create a GeoTools geometric multi-polygon primitive from coordinates in
 * json.
 * 
 * @param json the json array of polygons
 * @return the multi-polygon
 */
public static MultiPolygon createMultiPolygonFromJson( JsonNode json )
{
    // Native array of polygons to pass to GeoFactory
    Polygon[] polygons = new Polygon[MapUtils.getNonEmptyNodes( json )];

    // Read all the polygons from the json array
    for ( int i = 0; i < json.size(); i++ )
    {
        JsonNode node = json.get( i );

        if ( MapUtils.nodeIsNonEmpty( node ) )
        {
            polygons[i] = createPolygonFromJson( node );
        }
    }

    // Create the multi-polygon from factory
    return FACTORY.createMultiPolygon( polygons );
}
项目:UnitedTweetAnalyzer    文件:Geography.java   
/**
 * Query the polygons in our geography to find the country of the input coordinate.
 * @param coordinate the coordinate that needs to be queried.
 * @return the name of the coordinate state or UNKNOWN if not found.
 */
public String query(Coordinate coordinate) {
    final Point point = JTSFactoryFinder.getGeometryFactory().createPoint(coordinate);

    /** Before trying to locate the country,
     * we make sure that the point lies within
     * the specified bounding box.
     */
    if (!Geography.isInsideEnvelope(point)) {
        return UNKNOWN_COUNTRY;
    }

    for (Map.Entry<String, MultiPolygon> entry : this.polygons) {
        if (entry.getValue().contains(point)) {
            return entry.getKey();
        }
    }

    return UNKNOWN_COUNTRY;
}
项目:JInedit    文件:JTSUtil.java   
public static net.opengis.indoorgml.geometry.Polygon getConvexHull(List<net.opengis.indoorgml.geometry.Polygon> polygonList) {
    Polygon[] polygons = new Polygon[polygonList.size()];
    for (int i = 0; i < polygonList.size(); i++) {
        polygons[i] = convertJTSPolygon(polygonList.get(i));
    }

    MultiPolygon multiPolygon = gf.createMultiPolygon(polygons);
    ConvexHull convex = new ConvexHull(multiPolygon);
    Geometry convexHull = convex.getConvexHull();

    if (convexHull == null || !convexHull.getGeometryType().equals("Polygon")) {
        return null;
    }

    net.opengis.indoorgml.geometry.Polygon result = convertPolygon((Polygon) convexHull);
    return result;
}
项目:orientdb-spatial    文件:OMultiPolygonShapeBuilder.java   
@Override
public ODocument toDoc(JtsGeometry shape) {

  ODocument doc = new ODocument(getName());
  MultiPolygon multiPolygon = (MultiPolygon) shape.getGeom();
  List<List<List<List<Double>>>> polyCoordinates = new ArrayList<List<List<List<Double>>>>();
  int n = multiPolygon.getNumGeometries();

  for (int i = 0; i < n; i++) {
    Geometry geom = multiPolygon.getGeometryN(i);
    polyCoordinates.add(coordinatesFromPolygon((Polygon) geom));
  }

  doc.field(COORDINATES, polyCoordinates);
  return doc;
}
项目:AgileAlligators    文件:GeoToolsPrimitiveFromJsonFactory.java   
/**
 * Create a GeoTools geometric multi-polygon primitive from coordinates in
 * json.
 * 
 * @param json the json array of polygons
 * @return the multi-polygon
 * @throws JSONException
 */
public static MultiPolygon createMultiPolygonFromJson( JsonNode json )
{
    // Native array of polygons to pass to GeoFactory
    Polygon[] polygons = new Polygon[MapUtils.getNonEmptyNodes( json )];

    // Read all the polygons from the json array
    for ( int i = 0; i < json.size(); i++ )
    {
        JsonNode node = json.get( i );

        if ( MapUtils.nodeIsNonEmpty( node ) )
        {
            polygons[i] = createPolygonFromJson( node );
        }
    }

    // Create the multi-polygon from factory
    return FACTORY.createMultiPolygon( polygons );
}
项目:straightedge    文件:FogOfWarTest.java   
public MultiPolygon simplify(MultiPolygon jtsMultiPolygon){
    int numGeomtries = jtsMultiPolygon.getNumGeometries();
    Polygon[] newPolys = new Polygon[numGeomtries];
    for (int i = 0; i < numGeomtries; i++){
        Geometry geom = jtsMultiPolygon.getGeometryN(i);
        if (geom instanceof Polygon){
        //if (geom.getGeometryType().equals("MultiPolygon")){
            Polygon poly = (Polygon)geom;
            Polygon newPoly = simplify(poly);
            newPolys[i] = newPoly;
        }else{
            throw new RuntimeException("geom is not a polygon, geom == "+geom);
        }
    }
    return new MultiPolygon(newPolys, this.geometryFactory);
}
项目:gama    文件:GamaShape.java   
@Override
public GamaShape getExteriorRing(final IScope scope) {

    // WARNING Only in 2D
    Geometry result = getInnerGeometry();
    if (result instanceof Polygon) {
        result = ((Polygon) result).getExteriorRing();
    } else

    if (result instanceof MultiPolygon) {
        final MultiPolygon mp = (MultiPolygon) result;
        final LineString lines[] = new LineString[mp.getNumGeometries()];
        for (int i = 0; i < mp.getNumGeometries(); i++) {
            lines[i] = ((Polygon) mp.getGeometryN(i)).getExteriorRing();
        }
        result = GeometryUtils.GEOMETRY_FACTORY.createMultiLineString(lines);

    }
    return new GamaShape(result);
}
项目:gama    文件:SaveStatement.java   
public String getGeometryType(final List<? extends IShape> agents) {
    String geomType = "";
    for (final IShape be : agents) {
        final IShape geom = be.getGeometry();
        if (geom != null) {
            geomType = geom.getInnerGeometry().getClass().getSimpleName();
            if (geom.getInnerGeometry().getNumGeometries() > 1) {
                if (geom.getInnerGeometry().getGeometryN(0).getClass() == Point.class) {
                    geomType = MultiPoint.class.getSimpleName();
                } else if (geom.getInnerGeometry().getGeometryN(0).getClass() == LineString.class) {
                    geomType = MultiLineString.class.getSimpleName();
                } else if (geom.getInnerGeometry().getGeometryN(0).getClass() == Polygon.class) {
                    geomType = MultiPolygon.class.getSimpleName();
                }
                break;
            }
        }
    }

    if ("DynamicLineString".equals(geomType))
        geomType = LineString.class.getSimpleName();
    return geomType;
}
项目:RainInterpolator    文件:GridMaker.java   
/**
 * This methods works out what sort of feature geometry we have in the
 * shapefile and then delegates to an appropriate style creating method.
 */
private Style createStyle(FeatureSource featureSource) {
    SimpleFeatureType schema = (SimpleFeatureType) featureSource.getSchema();
    Class geomType = schema.getGeometryDescriptor().getType().getBinding();

    if (Polygon.class.isAssignableFrom(geomType)
            || MultiPolygon.class.isAssignableFrom(geomType)) {
        return createPolygonStyle();

    } else if (LineString.class.isAssignableFrom(geomType)
            || MultiLineString.class.isAssignableFrom(geomType)) {
        return createLineStyle();

    } else {
        return createPointStyle();
    }
}
项目:RainInterpolator    文件:ParseShapefiles.java   
private static GeometryTypeString parseGeometry(GeometryType type) {
    GeometryTypeString geometryType;
    //Geometry type
    Class<?> clazz = type.getBinding();

    if (Polygon.class.isAssignableFrom(clazz)
            || MultiPolygon.class.isAssignableFrom(clazz)) {
        geometryType = GeometryTypeString.POLYGON;

    } else if (LineString.class.isAssignableFrom(clazz)
            || MultiLineString.class.isAssignableFrom(clazz)) {
        geometryType = GeometryTypeString.LINE;

    } else {
        geometryType = GeometryTypeString.POINT;
    }
    return geometryType;
}
项目:platypus-js    文件:GeometryUtils.java   
public static boolean isValidGeometryData(List<Geometry> aData, Class aGeometryClass) {
    if (Point.class.isAssignableFrom(aGeometryClass)
            || LineString.class.isAssignableFrom(aGeometryClass)
            || Polygon.class.isAssignableFrom(aGeometryClass)) {
        return aData.size() == 1 && isValidGeometryDataSection(aData.get(0).getCoordinates(), aGeometryClass);
    } else if (MultiPoint.class.isAssignableFrom(aGeometryClass)
            || MultiLineString.class.isAssignableFrom(aGeometryClass)
            || MultiPolygon.class.isAssignableFrom(aGeometryClass)) {
        if (aData.size() >= 1) {
            for (int i = 0; i < aData.size(); i++) {
                if (!isValidGeometryDataSection(aData.get(i).getCoordinates(), aGeometryClass)) {
                    return false;
                }
            }
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
项目:geotools-cookbook    文件:StyleLab.java   
/**
 * Here is a programmatic alternative to using JSimpleStyleDialog to
 * get a Style. This methods works out what sort of feature geometry
 * we have in the shapefile and then delegates to an appropriate style
 * creating method.
 */
private Style createStyle2(FeatureSource featureSource) {
    SimpleFeatureType schema = (SimpleFeatureType)featureSource.getSchema();
    Class geomType = schema.getGeometryDescriptor().getType().getBinding();

    if (Polygon.class.isAssignableFrom(geomType)
            || MultiPolygon.class.isAssignableFrom(geomType)) {
        return createPolygonStyle();

    } else if (LineString.class.isAssignableFrom(geomType)
            || MultiLineString.class.isAssignableFrom(geomType)) {
        return createLineStyle();

    } else {
        return createPointStyle();
    }
}