コード例 #1
0
ファイル: GeoJSONBuilder.java プロジェクト: rishg/geoserver
  /**
   * Writes any geometry object. This class figures out which geometry representation to write and
   * calls subclasses to actually write the object.
   *
   * @param geometry The geometry to be encoded
   * @return The JSONBuilder with the new geometry
   * @throws JSONException If anything goes wrong
   */
  public JSONBuilder writeGeom(Geometry geometry) throws JSONException {
    this.object();
    this.key("type");
    this.value(getGeometryName(geometry));

    final int geometryType = getGeometryType(geometry);

    if (geometryType != MULTIGEOMETRY) {
      this.key("coordinates");

      switch (geometryType) {
        case POINT:
          Point point = (Point) geometry;
          Coordinate c = point.getCoordinate();
          writeCoordinate(c.x, c.y, c.z);
          break;
        case LINESTRING:
          writeCoordinates(((LineString) geometry).getCoordinateSequence());
          break;
        case MULTIPOINT:
          writeCoordinates(geometry.getCoordinates());
          break;
        case POLYGON:
          writePolygon((Polygon) geometry);

          break;

        case MULTILINESTRING:
          this.array();

          for (int i = 0, n = geometry.getNumGeometries(); i < n; i++) {
            writeCoordinates(((LineString) geometry.getGeometryN(i)).getCoordinateSequence());
          }

          this.endArray();

          break;

        case MULTIPOLYGON:
          this.array();

          for (int i = 0, n = geometry.getNumGeometries(); i < n; i++) {
            writePolygon((Polygon) geometry.getGeometryN(i));
          }

          this.endArray();

          break;
      }
    } else {
      writeGeomCollection((GeometryCollection) geometry);
    }

    return this.endObject();
  }
コード例 #2
0
  private static boolean multiPolygonToMultiLine(
      Geometry geom, Class<? extends Geometry> targetType, Collection<Geometry> result) {
    if (geom instanceof MultiPolygon && MultiLineString.class == targetType) {

      for (int i = 0; i < geom.getNumGeometries(); i++) {
        if (!polygonToMultiLine(geom.getGeometryN(i), targetType, result))
          throw new RuntimeException(
              "Huh?  multi polygons should only have polygons in them, found a "
                  + geom.getGeometryN(i)); // $NON-NLS-1$
      }

      return true;
    }
    return false;
  }
コード例 #3
0
 /** Write an Array of "full" Geometries */
 private int estimateGeometryArray(Geometry container) {
   int result = 0;
   for (int i = 0; i < container.getNumGeometries(); i++) {
     result += estimateBytes(container.getGeometryN(i));
   }
   return result;
 }
コード例 #4
0
  /**
   * Each edge will be built with 2 coordinates.
   *
   * @param intersectingLineStrings The geometry which edges will be based on.
   * @param onLoc position for ON.
   * @param leftLoc position for LEFT.
   * @param rightLoc position for RIGHT.
   */
  private void insertEdge(
      final Geometry intersectingLineStrings,
      final Geometry holeGeometries,
      final int onLoc,
      final int leftLoc,
      final int rightLoc) {

    for (int i = 0; i < intersectingLineStrings.getNumGeometries(); i++) {

      Geometry intersectingSegment = intersectingLineStrings.getGeometryN(i);

      if ((intersectingSegment.getNumPoints() == 2) && !holeGeometries.isEmpty()) {
        // special case, when the line has 2 coordinates and
        // its orientation can't be calculated because it hasn't.
        intersectingSegment = adjustSegmentToHoleDirection(intersectingSegment, holeGeometries);
      }

      Coordinate[] coords = intersectingSegment.getCoordinates();
      for (int j = 0; j < coords.length - 1; j++) {

        final SplitEdge edge =
            SplitEdge.newInstance(coords[j], coords[j + 1], onLoc, leftLoc, rightLoc);

        // add the list that only contains one edge because it will
        // create 2 directedEdge.
        this.graph.addEdge(edge);
      }
    }
  }
コード例 #5
0
ファイル: Geo.java プロジェクト: runeengh/basex
 /**
  * Returns the nth geometry of a geometry collection, or the geometry if the input is not a
  * collection.
  *
  * @param node xml element containing gml object(s)
  * @param number integer number as the index of nth geometry
  * @return geometry as a gml element
  * @throws QueryException query exception
  */
 @Deterministic
 public ANode geometryN(final ANode node, final Int number) throws QueryException {
   final Geometry geo = checkGeo(node);
   final long n = number.itr();
   if (n < 1 || n > geo.getNumGeometries()) throw GeoErrors.outOfRangeIdx(number);
   return gmlWriter(geo.getGeometryN((int) n - 1));
 }
コード例 #6
0
ファイル: LinearIterator.java プロジェクト: Gnafu/SIIGMobile
 private void loadCurrentLine() {
   if (componentIndex >= numLines) {
     currentLine = null;
     return;
   }
   currentLine = (LineString) linearGeom.getGeometryN(componentIndex);
 }
コード例 #7
0
  /**
   * Tests whether a geometry consists of a single polygon with no holes.
   *
   * @return true if the geometry is a single polygon with no holes
   */
  private boolean isSingleShell(Geometry geom) {
    // handles single-element MultiPolygons, as well as Polygons
    if (geom.getNumGeometries() != 1) return false;

    Polygon poly = (Polygon) geom.getGeometryN(0);
    int numHoles = poly.getNumInteriorRing();
    if (numHoles == 0) return true;
    return false;
  }
コード例 #8
0
ファイル: ST_GeomUnion.java プロジェクト: JimmyFarcy/orbisgis
 private void addGeometry(Geometry geom) {
   if (geom.getGeometryType().equals("GeometryCollection")) {
     for (int i = 0; i < geom.getNumGeometries(); i++) {
       addGeometry(geom.getGeometryN(i));
     }
   } else {
     toUnite.add(geom);
   }
 }
コード例 #9
0
 private static boolean collectionToPoint(
     Geometry geom, Class<? extends Geometry> targetType, Collection<Geometry> result) {
   if (geom instanceof GeometryCollection && Point.class == targetType) {
     for (int i = 0; i < geom.getNumGeometries(); i++) {
       result.add(geom.getGeometryN(i).getCentroid());
     }
     return true;
   }
   return false;
 }
コード例 #10
0
ファイル: Yemen.java プロジェクト: galdolber/worldboundaries
 public static boolean test(Point p) {
   if ((p.getX() >= 53.25666000000001
           && p.getY() >= 12.106109999999944
           && p.getX() <= 53.340828000000094
           && p.getY() <= 12.134442999999976)
       || (p.getX() >= 53.011383000000016
           && p.getY() >= 12.13305500000007
           && p.getX() <= 53.11332700000008
           && p.getY() <= 12.181389000000138)
       || (p.getX() >= 52.08305399999995
           && p.getY() >= 12.144721999999945
           && p.getX() <= 52.397217000000126
           && p.getY() <= 12.2469440000001)
       || (p.getX() >= 43.39138799999994
           && p.getY() >= 12.630278000000088
           && p.getX() <= 43.450554000000125
           && p.getY() <= 12.67388699999998)
       || (p.getX() >= 53.325829
           && p.getY() >= 12.30805400000014
           && p.getX() <= 54.47694400000007
           && p.getY() <= 12.717777000000067)
       || (p.getX() >= 42.67527800000005
           && p.getY() >= 13.660000000000082
           && p.getX() <= 42.79721800000005
           && p.getY() <= 13.782775999999956)
       || (p.getX() >= 42.68916300000012
           && p.getY() >= 13.909443000000124
           && p.getX() <= 42.79999500000014
           && p.getY() <= 14.066944000000092)
       || (p.getX() >= 42.55583200000012
           && p.getY() >= 15.270831999999984
           && p.getX() <= 42.65972099999999
           && p.getY() <= 15.458331999999984)
       || (p.getX() >= 42.67999300000008
           && p.getY() >= 12.592776999999955
           && p.getX() <= 53.114441000000056
           && p.getY() <= 18.99934400000012)) {
     byte[] data;
     try {
       data =
           ByteStreams.toByteArray(
               Antarctica.class.getClassLoader().getResourceAsStream("com/country/Yemen.data"));
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
     Geometry geo = Util.convert(data);
     for (int i = 0; i < geo.getNumGeometries(); i++) {
       if (geo.getGeometryN(i).contains(p)) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #11
0
  private static boolean multiPolygonToPolygon(
      Geometry geom, Class<? extends Geometry> targetType, Collection<Geometry> result) {
    if (geom instanceof MultiPolygon && Polygon.class == targetType) {
      for (int j = 0; j < geom.getNumGeometries(); j++) {
        result.add(geom.getGeometryN(j));
      }

      return true;
    }
    return false;
  }
コード例 #12
0
 private static boolean collectionToMultiPoint(
     Geometry geom, Class<? extends Geometry> targetType, Collection<Geometry> result) {
   if (geom instanceof GeometryCollection && MultiPoint.class == targetType) {
     Point[] points = new Point[geom.getNumGeometries()];
     for (int i = 0; i < geom.getNumGeometries(); i++) {
       points[i] = geom.getGeometryN(i).getCentroid();
     }
     result.add(geomBuilder.factory.createMultiPoint(points));
     return true;
   }
   return false;
 }
コード例 #13
0
 public boolean acceptGeometry(Geometry geom) {
   if (geom.getGeometryType().equals("GeometryCollection")) {
     for (int i = 0; i < geom.getNumGeometries(); i++) {
       if (acceptGeometry(geom.getGeometryN(i))) {
         return true;
       }
     }
     return false;
   } else {
     return willDrawSimpleGeometry(geom);
   }
 }
コード例 #14
0
  static Geometry densify(Geometry geom, CoordinateReferenceSystem crs, double maxAreaError)
      throws FactoryException, TransformException {
    // basic checks
    if (maxAreaError <= 0) {
      throw new IllegalArgumentException("maxAreaError must be greater than 0");
    }
    if (!(geom instanceof Polygon) && !(geom instanceof MultiPolygon)) {
      throw new IllegalArgumentException("Geom must be poligonal");
    }
    if (crs == null) {
      throw new IllegalArgumentException("CRS cannot be set to null");
    }
    double previousArea = 0.0;
    CoordinateReferenceSystem targetCRS = CRS.parseWKT(ECKERT_IV_WKT);
    MathTransform firstTransform = CRS.findMathTransform(crs, targetCRS);
    GeometryFactory geomFactory = new GeometryFactory();
    int ngeom = geom.getNumGeometries();
    Geometry densifiedGeometry = geom;
    double areaError = 1.0d;
    int maxIterate = 0;
    do {
      double max = 0;
      maxIterate++;
      // check the maximum side length of the densifiedGeometry
      for (int j = 0; j < ngeom; j++) {
        Geometry geometry = densifiedGeometry.getGeometryN(j);
        Coordinate[] coordinates = geometry.getCoordinates();
        int n = coordinates.length;
        for (int i = 0; i < (n - 1); i++) {
          Coordinate[] coords = new Coordinate[2];
          coords[0] = coordinates[i];
          coords[1] = coordinates[i + 1];
          LineString lineString = geomFactory.createLineString(coords);
          if (lineString.getLength() > max) max = lineString.getLength();
        }
      }

      // calculate the denified geometry
      densifiedGeometry = Densifier.densify(densifiedGeometry, max / 2);

      // reproject densifiedGeometry to Eckert IV
      Geometry targetGeometry = JTS.transform(densifiedGeometry, firstTransform);
      double nextArea = targetGeometry.getArea();

      // evaluate the current error
      areaError = Math.abs(previousArea - nextArea) / nextArea;
      //      logger3.info("AREA ERROR"+areaError);
      previousArea = nextArea;
      // check whether the current error is greater than the maximum allowed
    } while (areaError > maxAreaError && maxIterate < 10);
    return densifiedGeometry;
  }
コード例 #15
0
  private MapDisplayer calculateMapBoundingBox() throws TransformException {
    /* Identify extreme values for the X and Y dimensions
     * among the Geometries in our featureCollection.
     * Note that this is *after* Geometry preparation (cropping and projecting).
     */
    double dataMinX = Double.POSITIVE_INFINITY;
    double dataMinY = Double.POSITIVE_INFINITY;
    double dataMaxX = Double.NEGATIVE_INFINITY;
    double dataMaxY = Double.NEGATIVE_INFINITY;
    FeatureIterator<SimpleFeature> it = featureCollection.features();
    while (it.hasNext()) {
      SimpleFeature feature = it.next();
      Geometry rawGeometry = (Geometry) feature.getDefaultGeometry();
      Geometry geometry = geometryProjector.projectGeometry(rawGeometry);

      for (int gg = 0; gg < geometry.getNumGeometries(); gg++) {
        Geometry subgeometry = geometry.getGeometryN(gg);

        Coordinate[] coordinates = subgeometry.getCoordinates();

        for (Coordinate coordinate : coordinates) {
          if (coordinate.x < dataMinX) {
            dataMinX = coordinate.x;
          }
          if (coordinate.y < dataMinY) {
            dataMinY = coordinate.y;
          }
          if (coordinate.x > dataMaxX) {
            dataMaxX = coordinate.x;
          }
          if (coordinate.y > dataMaxY) {
            dataMaxY = coordinate.y;
          }
        }
      }
    }
    // YOU MUST CLOSE THE ITERATOR!
    it.close();

    // Exaggerate the data range a bit to provide a buffer around it in the map.
    double xRange = dataMaxX - dataMinX;
    double xBufferSize = MAP_BOUNDING_BOX_BUFFER_RATIO * xRange;
    double bufferedDataMinX = dataMinX - xBufferSize;
    double bufferedDataMaxX = dataMaxX + xBufferSize;

    double yRange = dataMaxY - dataMinY;
    double yBufferSize = MAP_BOUNDING_BOX_BUFFER_RATIO * yRange;
    double bufferedDataMinY = dataMinY - yBufferSize;
    double bufferedDataMaxY = dataMaxY + yBufferSize;

    return new MapDisplayer(bufferedDataMinX, bufferedDataMinY, bufferedDataMaxX, bufferedDataMaxY);
  }
コード例 #16
0
 private static boolean collectionToMultiPolygon(
     Geometry geom, Class<? extends Geometry> targetType, Collection<Geometry> result) {
   if (!(geom instanceof Polygon)
       && geom instanceof GeometryCollection
       && MultiPolygon.class == targetType) {
     for (int i = 0; i < geom.getNumGeometries(); i++) {
       result.add(
           geomBuilder.safeCreateGeometry(targetType, geom.getGeometryN(i).getCoordinates()));
     }
     return true;
   }
   return false;
 }
コード例 #17
0
  /**
   * converts the collection of holes (LineString) to a List of String
   *
   * @param holeGeometries
   * @return List of holes as LineString
   */
  private List<LineString> convertHolesGeometriesToHoleList(final Geometry holeGeometries) {

    assert holeGeometries != null;

    List<LineString> holeList = new ArrayList<LineString>(holeGeometries.getNumGeometries());

    for (int i = 0; i < holeGeometries.getNumGeometries(); i++) {

      LineString hole = (LineString) holeGeometries.getGeometryN(i);
      holeList.add(hole);
    }
    return holeList;
  }
コード例 #18
0
  /**
   * @param toSplit the line to split
   * @param line the line to use for the split
   * @return a sorted list of geometries as a result of splitting toSplit with line
   */
  protected List<LineString> splitLine(Geometry toSplit, Geometry line) {
    List<LineString> output = new ArrayList();
    Geometry lines = toSplit.union(line);

    for (int i = 0; i < lines.getNumGeometries(); i++) {
      LineString l = (LineString) lines.getGeometryN(i);
      // TODO to be tested
      if (toSplit.contains(l.getInteriorPoint())) {
        output.add(l);
      }
    }
    geometrySorter(output);
    return output;
  }
コード例 #19
0
 public static final int getCoordDim(Geometry geom) {
   if (geom.isEmpty()) {
     return 0;
   }
   if (geom instanceof Point) {
     return getCoordSequenceDim(((Point) geom).getCoordinateSequence());
   } else if (geom instanceof LineString) {
     return getCoordSequenceDim(((LineString) geom).getCoordinateSequence());
   } else if (geom instanceof Polygon) {
     return getCoordSequenceDim(((Polygon) geom).getExteriorRing().getCoordinateSequence());
   } else {
     return getCoordDim(geom.getGeometryN(0));
   }
 }
コード例 #20
0
 private static boolean collectionToMultiLine(
     Geometry geom, Class<? extends Geometry> targetType, Collection<Geometry> result) {
   if (!(geom instanceof Polygon)
       && !(geom instanceof MultiPolygon)
       && (geom instanceof GeometryCollection)
       && MultiLineString.class == targetType) {
     LineString[] geoms = new LineString[geom.getNumGeometries()];
     for (int i = 0; i < geom.getNumGeometries(); i++) {
       geoms[i] =
           geomBuilder.safeCreateGeometry(LineString.class, geom.getGeometryN(i).getCoordinates());
     }
     result.add(geomBuilder.factory.createMultiLineString(geoms));
     return true;
   }
   return false;
 }
コード例 #21
0
  public void addOSMEdgeToSpatialIndex(OSMEdge osmEdge) {
    // System.out.println("added edge with ID " + osmEdge.getId());
    // counter__edge.put(osmEdge.getId(), osmEdge.getGeometry());	// store edges in the hash map

    Geometry env = osmEdge.getGeometry().getBoundary();
    //  (minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy), (minx, miny).

    if (env.getNumGeometries() > 0) {
      Point p1 = (Point) env.getGeometryN(0);
      Point p2 = (Point) env.getGeometryN(1);

      si.add(
          new Rectangle((float) p1.getX(), (float) p1.getY(), (float) p2.getX(), (float) p2.getY()),
          osmEdge.getId());
    }
  }
コード例 #22
0
  /**
   * @param poly the polygon to split
   * @param line the line to use for the split
   * @return a sorted list of geometries as a result of splitting poly with line
   */
  protected List<Polygon> splitPolygon(Geometry poly, Geometry line) {
    List<Polygon> output = new ArrayList();

    Geometry nodedLinework = poly.getBoundary().union(line);
    Geometry polys = polygonize(nodedLinework);

    // only keep polygons which are inside the input
    for (int i = 0; i < polys.getNumGeometries(); i++) {
      Polygon candpoly = (Polygon) polys.getGeometryN(i);
      if (poly.contains(candpoly.getInteriorPoint())) {
        output.add(candpoly);
      }
    }
    geometrySorter(output);
    return output;
  }
コード例 #23
0
  private void setCurrentFeature(final Feature feature) {
    this.feature = feature;
    this.geometry = null;
    this.subGeometries.clear();

    if (feature != null) {
      this.geometry = helper.toObjectiveCRS(feature);
      if (geometry != null) {
        geometry.clone();
        multipolygon = (geometry instanceof MultiPolygon);
        for (int i = 0; i < geometry.getNumGeometries(); i++) {
          subGeometries.add(geometry.getGeometryN(i));
        }
      }
    }
    decoration.setGeometries(Collections.singleton(this.geometry));
  }
コード例 #24
0
  /**
   * Adds the geometries present in the intersection result if they are {@link LineString} into the
   * geometry list
   *
   * @param intersectResult
   * @param geometryList
   * @return the geometry list updated with the geometries intersection
   */
  private List<Geometry> addLinesInCommon(Geometry intersectResult, List<Geometry> geometryList) {

    if (intersectResult instanceof GeometryCollection) {
      // get the lineString or multiLineString instances
      for (int i = 0; i < intersectResult.getNumGeometries(); i++) {

        Geometry part = intersectResult.getGeometryN(i);
        if (part instanceof LineString || part instanceof MultiLineString) {
          geometryList.add(part);
        }
      }
    } else if (intersectResult instanceof LineString
        || intersectResult instanceof MultiLineString) {
      geometryList.add(intersectResult);
    }
    return geometryList;
  }
コード例 #25
0
  /**
   * Computes the angle from the first point to the last point of a LineString or MultiLineString.
   * TODO: put this method into org.opentripplanner.common.geometry.DirectionUtils
   *
   * @param geometry a LineString or a MultiLineString
   * @return
   */
  public synchronized double getFirstToLastSegmentAngle(Geometry geometry) {
    LineString line;
    if (geometry instanceof MultiLineString) {
      line = (LineString) geometry.getGeometryN(geometry.getNumGeometries() - 1);
    } else {
      assert geometry instanceof LineString;
      line = (LineString) geometry;
    }
    int numPoints = line.getNumPoints();
    Coordinate coord0 = line.getCoordinateN(0);
    Coordinate coord1 = line.getCoordinateN(numPoints - 1);
    int i = numPoints - 3;
    while (distanceLibrary.fastDistance(coord0, coord1) < 10 && i >= 0) {
      coord1 = line.getCoordinateN(i--);
    }

    geodeticCalculator.setStartingGeographicPoint(coord0.x, coord0.y);
    geodeticCalculator.setDestinationGeographicPoint(coord1.x, coord1.y);
    return geodeticCalculator.getAzimuth() * Math.PI / 180;
  }
コード例 #26
0
  /**
   * Only return the lines contained on the given geometry, the non lines geometry are rejected.
   *
   * @param geometry Intersection geometry between split line and source geometry.
   * @return The valid geometries needed for the graph, those are lines and multiLines.
   */
  private Geometry filterLineString(Geometry geometry) {

    List<Geometry> filteredLines = new ArrayList<Geometry>();
    for (int i = 0; i < geometry.getNumGeometries(); i++) {

      Geometry possibleLine = geometry.getGeometryN(i);

      // if there are point geometries, discard it.
      if (possibleLine instanceof LineString || possibleLine instanceof MultiLineString) {

        // also remove very very short liens.
        if (possibleLine.getLength() > UsefulSplitLineBuilder.DEPRECIATE_VALUE) {

          filteredLines.add(possibleLine);
        }
      }
    }
    GeometryFactory gf = geometry.getFactory();

    return gf.buildGeometry(filteredLines);
  }
コード例 #27
0
 public static boolean test(Point p) {
   if ((p.getX() >= 105.628998
       && p.getY() >= -10.51097
       && p.getX() <= 105.7519
       && p.getY() <= -10.38408)) {
     byte[] data;
     try {
       data =
           ByteStreams.toByteArray(
               Antarctica.class
                   .getClassLoader()
                   .getResourceAsStream("com/country/ChristmasIsland.data"));
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
     Geometry geo = Util.convert(data);
     for (int i = 0; i < geo.getNumGeometries(); i++) {
       if (geo.getGeometryN(i).contains(p)) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #28
0
ファイル: Japan.java プロジェクト: galdolber/worldboundaries
 public static boolean test(Point p) {
   if ((p.getX() >= 153.93887299999994
           && p.getY() >= 24.29277400000001
           && p.getX() <= 153.96579000000006
           && p.getY() <= 24.321663)
       || (p.getX() >= 123.67886399999996
           && p.getY() >= 24.250832000000003
           && p.getX() <= 123.93665300000008
           && p.getY() <= 24.418053000000043)
       || (p.getX() >= 122.93525700000008
           && p.getY() >= 24.434719000000033
           && p.getX() <= 123.01805100000013
           && p.getY() <= 24.470828999999924)
       || (p.getX() >= 131.239685
           && p.getY() >= 24.454441000000088
           && p.getX() <= 131.27636700000016
           && p.getY() <= 24.486381999999992)
       || (p.getX() >= 124.07582100000002
           && p.getY() >= 24.32722100000001
           && p.getX() <= 124.330551
           && p.getY() <= 24.588051000000007)
       || (p.getX() >= 141.28442400000003
           && p.getY() >= 24.725273000000072
           && p.getX() <= 141.36358600000003
           && p.getY() <= 24.794163000000083)
       || (p.getX() >= 125.25221299999998
           && p.getY() >= 24.71610600000008
           && p.getX() <= 125.4511030000001
           && p.getY() <= 24.884440999999924)
       || (p.getX() >= 141.26608300000007
           && p.getY() >= 25.417774000000065
           && p.getX() <= 141.30191000000002
           && p.getY() <= 25.454162999999937)
       || (p.getX() >= 131.20800800000006
           && p.getY() >= 25.8127750000001
           && p.getX() <= 131.27386500000011
           && p.getY() <= 25.87249800000012)
       || (p.getX() >= 126.69193299999995
           && p.getY() >= 26.296944
           && p.getX() <= 126.81109600000002
           && p.getY() <= 26.387774999999976)
       || (p.getX() >= 142.10913100000002
           && p.getY() >= 26.612217000000044
           && p.getX() <= 142.17776500000002
           && p.getY() <= 26.71666299999993)
       || (p.getX() >= 127.63997700000003
           && p.getY() >= 26.078609000000085
           && p.getX() <= 128.33551000000014
           && p.getY() <= 26.854996000000085)
       || (p.getX() >= 142.17608600000003
           && p.getY() >= 27.032496999999974
           && p.getX() <= 142.2402340000001
           && p.getY() <= 27.095276000000126)
       || (p.getX() >= 142.178589
           && p.getY() >= 27.145550000000128
           && p.getX() <= 142.204132
           && p.getY() <= 27.191105000000107)
       || (p.getX() >= 140.86245700000015
           && p.getY() >= 27.218327000000045
           && p.getX() <= 140.881622
           && p.getY() <= 27.24360700000005)
       || (p.getX() >= 128.52249100000017
           && p.getY() >= 27.346663999999976
           && p.getX() <= 128.70385700000008
           && p.getY() <= 27.4486050000001)
       || (p.getX() >= 142.16998300000012
           && p.getY() >= 27.59916300000009
           && p.getX() <= 142.19940200000008
           && p.getY() <= 27.625275000000045)
       || (p.getX() >= 142.068848
           && p.getY() >= 27.71693800000014
           && p.getX() <= 142.09164399999997
           && p.getY() <= 27.732773000000066)
       || (p.getX() >= 128.8802489999999
           && p.getY() >= 27.675552000000096
           && p.getX() <= 129.02996799999994
           && p.getY() <= 27.907497000000088)
       || (p.getX() >= 129.18469200000004
           && p.getY() >= 28.075275000000037
           && p.getX() <= 129.35385100000008
           && p.getY() <= 28.191395000000117)
       || (p.getX() >= 129.91442900000004
           && p.getY() >= 28.279999000000032
           && p.getX() <= 130.0330510000001
           && p.getY() <= 28.366385999999977)
       || (p.getX() >= 129.14303600000002
           && p.getY() >= 28.115273
           && p.getX() <= 129.71829200000002
           && p.getY() <= 28.497719000000014)
       || (p.getX() >= 129.70608500000003
           && p.getY() >= 29.60638399999999
           && p.getX() <= 129.75332600000016
           && p.getY() <= 29.663330000000087)
       || (p.getX() >= 129.851898
           && p.getY() >= 29.81805399999996
           && p.getX() <= 129.923309
           && p.getY() <= 29.87694200000004)
       || (p.getX() >= 129.92358400000015
           && p.getY() >= 29.956383000000127
           && p.getX() <= 129.97106900000003
           && p.getY() <= 30.00166300000012)
       || (p.getX() >= 130.38024900000005
           && p.getY() >= 30.235828000000083
           && p.getX() <= 130.67190600000004
           && p.getY() <= 30.460827000000048)
       || (p.getX() >= 140.30136100000016
           && p.getY() >= 30.458328000000048
           && p.getX() <= 140.335785
           && p.getY() <= 30.48388300000005)
       || (p.getX() >= 130.86163300000007
           && p.getY() >= 30.353607000000068
           && p.getX() <= 131.08551000000003
           && p.getY() <= 30.84027500000002)
       || (p.getX() >= 129.67053199999998
           && p.getY() >= 31.631107000000043
           && p.getX() <= 129.80191000000002
           && p.getY() <= 31.793331000000023)
       || (p.getX() >= 139.99939000000006
           && p.getY() >= 31.93110700000005
           && p.getX() <= 140.028595
           && p.getY() <= 31.946663)
       || (p.getX() >= 130.10885599999995
           && p.getY() >= 32.10804700000011
           && p.getX() <= 130.1955260000001
           && p.getY() <= 32.21666000000005)
       || (p.getX() >= 130.20773300000008
           && p.getY() >= 32.370544000000045
           && p.getX() <= 130.44802900000002
           && p.getY() <= 32.522217000000126)
       || (p.getX() >= 129.95523100000003
           && p.getY() >= 32.188315999999986
           && p.getX() <= 130.21109
           && p.getY() <= 32.54361)
       || (p.getX() >= 128.60107400000015
           && p.getY() >= 32.58915700000006
           && p.getX() <= 128.902191
           && p.getY() <= 32.79249599999997)
       || (p.getX() >= 129.00555399999996
           && p.getY() >= 32.81638300000003
           && p.getX() <= 129.1830440000001
           && p.getY() <= 33.145546000000024)
       || (p.getX() >= 139.73968500000012
           && p.getY() >= 33.03472100000005
           && p.getX() <= 139.87219200000004
           && p.getY() <= 33.147491)
       || (p.getX() >= 129.35995500000013
           && p.getY() >= 33.164710999999954
           && p.getX() <= 129.569702
           && p.getY() <= 33.389717000000125)
       || (p.getX() >= 129.81359899999998
           && p.getY() >= 33.3394320000001
           && p.getX() <= 129.86108400000015
           && p.getY() <= 33.39860500000009)
       || (p.getX() >= 132.18551600000012
           && p.getY() >= 33.75443999999999
           && p.getX() <= 132.27609300000006
           && p.getY() <= 33.79610400000007)
       || (p.getX() >= 129.65887500000008
           && p.getY() >= 33.69748699999997
           && p.getX() <= 129.79412800000011
           && p.getY() <= 33.85694100000006)
       || (p.getX() >= 139.58136000000013
           && p.getY() >= 33.83194000000009
           && p.getX() <= 139.626892
           && p.getY() <= 33.88916000000012)
       || (p.getX() >= 129.56387299999994
           && p.getY() >= 30.99666200000001
           && p.getX() <= 131.98941000000002
           && p.getY() <= 33.936653000000035)
       || (p.getX() >= 132.18441800000002
           && p.getY() >= 33.84915899999993
           && p.getX() <= 132.45163000000002
           && p.getY() <= 33.94748700000014)
       || (p.getX() >= 139.48217799999998
           && p.getY() >= 34.03221100000002
           && p.getX() <= 139.57440199999996
           && p.getY() <= 34.110550000000046)
       || (p.getX() >= 132.456635
           && p.getY() >= 34.061104
           && p.getX() <= 132.585236
           && p.getY() <= 34.182495000000074)
       || (p.getX() >= 132.38552900000002
           && p.getY() >= 34.11415900000003
           && p.getX() <= 132.49883999999997
           && p.getY() <= 34.279160000000104)
       || (p.getX() >= 132.94998199999998
           && p.getY() >= 34.184990000000084
           && p.getX() <= 133.05554200000006
           && p.getY() <= 34.29415899999998)
       || (p.getX() >= 129.18331899999998
           && p.getY() >= 34.07360800000004
           && p.getX() <= 129.34939600000007
           && p.getY() <= 34.32222000000007)
       || (p.getX() >= 132.015808
           && p.getY() >= 32.735550000000046
           && p.getX() <= 134.75305200000003
           && p.getY() <= 34.38749700000011)
       || (p.getX() >= 139.24856599999998
           && p.getY() >= 34.31721500000003
           && p.getX() <= 139.30246
           && p.getY() <= 34.41971600000011)
       || (p.getX() >= 134.1927489999999
           && p.getY() >= 34.42860400000012
           && p.getX() <= 134.3715820000001
           && p.getY() <= 34.551383999999985)
       || (p.getX() >= 134.660522
           && p.getY() >= 34.18443300000001
           && p.getX() <= 135.02804600000013
           && p.getY() <= 34.59526800000009)
       || (p.getX() >= 129.24523900000008
           && p.getY() >= 34.29471600000005
           && p.getX() <= 129.50582900000006
           && p.getY() <= 34.690269000000114)
       || (p.getX() >= 139.35858199999996
           && p.getY() >= 34.66944100000006
           && p.getX() <= 139.45831299999998
           && p.getY() <= 34.78777300000013)
       || (p.getX() >= 133.01080300000012
           && p.getY() >= 35.989716000000044
           && p.getX() <= 133.07663000000014
           && p.getY() <= 36.02249100000006)
       || (p.getX() >= 133.07440199999996
           && p.getY() >= 36.02027100000004
           && p.getX() <= 133.13388099999997
           && p.getY() <= 36.10332499999993)
       || (p.getX() >= 132.95053100000007
           && p.getY() >= 36.03166199999998
           && p.getX() <= 133.0916440000001
           && p.getY() <= 36.12526700000001)
       || (p.getX() >= 133.1824650000001
           && p.getY() >= 36.151382000000005
           && p.getX() <= 133.38525400000015
           && p.getY() <= 36.32499700000011)
       || (p.getX() >= 136.90942400000017
           && p.getY() >= 37.089432000000045
           && p.getX() <= 137.05801400000007
           && p.getY() <= 37.154991)
       || (p.getX() >= 138.20913700000003
           && p.getY() >= 37.79361000000006
           && p.getX() <= 138.58108500000014
           && p.getY() <= 38.322495)
       || (p.getX() >= 130.87966900000004
           && p.getY() >= 33.454994
           && p.getX() <= 142.069702
           && p.getY() <= 41.530273000000136)
       || (p.getX() >= 139.40774499999998
           && p.getY() >= 42.047217999999994
           && p.getX() <= 139.56301900000017
           && p.getY() <= 42.237770000000125)
       || (p.getX() >= 145.22000100000014
           && p.getY() >= 43.536662999999976
           && p.getX() <= 145.36108400000012
           && p.getY() <= 43.60255100000012)
       || (p.getX() >= 143.81192
           && p.getY() >= 44.140549000000014
           && p.getX() <= 143.97051999999996
           && p.getY() <= 44.17276800000008)
       || (p.getX() >= 141.12744099999998
           && p.getY() >= 45.09693900000001
           && p.getX() <= 141.33468600000003
           && p.getY() <= 45.25138899999996)
       || (p.getX() >= 140.96801800000014
           && p.getY() >= 45.26471699999996
           && p.getX() <= 141.07440200000008
           && p.getY() <= 45.46554600000008)
       || (p.getX() >= 139.76831100000004
           && p.getY() >= 41.39499699999999
           && p.getX() <= 145.82220500000003
           && p.getY() <= 45.486382000000106)) {
     byte[] data;
     try {
       data =
           ByteStreams.toByteArray(
               Antarctica.class.getClassLoader().getResourceAsStream("com/country/Japan.data"));
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
     Geometry geo = Util.convert(data);
     for (int i = 0; i < geo.getNumGeometries(); i++) {
       if (geo.getGeometryN(i).contains(p)) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #29
0
  public void writeFeatures(List<Feature> features) throws KettleException {

    Kml kml = new Kml();
    Document document = kml.createAndSetDocument();

    if (this.documentName != null) {
      document.setName(documentName);
    }

    if (this.documentDescription != null) {
      document.setDescription(documentDescription);
    }

    // Si export des attributs
    if (exportWithAttributs) {

      Schema schema = document.createAndAddSchema();
      schema.setId("dataSchema");
      schema.setName("");

      Iterator<Field> fieldIt = this.fields.iterator();
      while (fieldIt.hasNext()) {

        Field field = fieldIt.next();

        // Pas pris en compte ici : une seule géométrie
        if (!field.getType().equals(FieldType.GEOMETRY)) {

          SimpleField simpleField = schema.createAndAddSimpleField();
          simpleField.setName(field.getName());

          // Texte
          if (field.getType().equals(FieldType.STRING)) {

            simpleField.setType("string");

            // Date
          } else if (field.getType().equals(FieldType.DATE)) {

            simpleField.setType("date");

            // Entier
          } else if (field.getType().equals(FieldType.LONG)) {

            simpleField.setType("int");

            // Double
          } else if (field.getType().equals(FieldType.DOUBLE)) {

            simpleField.setType("float");

            // Booléen
          } else if (field.getType().equals(FieldType.BOOLEAN)) {

            simpleField.setType("bool");

            // Autres types
          } else {
            simpleField.setType("string");
          }
        }
      }
    }

    // Récupération des champs utilisés
    Field geometryField = null;
    Field nameField = null;
    Field descriptionField = null;

    Iterator<Feature> featureIt = features.iterator();
    boolean first = true;
    while (featureIt.hasNext()) {

      Feature feature = featureIt.next();
      if (first) {

        geometryField = feature.getField(this.geometryFieldName);

        if (featureNameField != null) {
          nameField = feature.getField(this.featureNameField);
        }

        if (featureDescriptionField != null) {
          descriptionField = feature.getField(this.featureDescriptionField);
        }

        first = false;
      }

      Geometry geometry = (Geometry) feature.getValue(geometryField);
      Envelope envelope = geometry.getEnvelopeInternal();

      // Vérification de l'emprise : doit être en WGS 84
      if (envelope.getMaxX() > 180
          || envelope.getMinX() < -180
          || envelope.getMaxY() > 90
          || envelope.getMinY() < -90) {

        throw new KettleException("Bad coordinates for WGS84 system");
      }

      Placemark placemark = document.createAndAddPlacemark();

      // Nom de feature
      if (featureNameField != null) {
        String name = (String) feature.getValue(nameField);
        if (name != null) {
          placemark.setName(name);
        }
      }

      // Description de feature
      if (featureDescriptionField != null) {
        String description = (String) feature.getValue(descriptionField);
        if (description != null) {
          placemark.setDescription(description);
        }
      }

      // Attributs
      if (exportWithAttributs) {
        ExtendedData extendedData = placemark.createAndSetExtendedData();
        SchemaData schemaData = extendedData.createAndAddSchemaData();
        schemaData.setSchemaUrl("dataSchema");

        Iterator<Field> colIt = this.fields.iterator();
        while (colIt.hasNext()) {

          Field field = colIt.next();
          if (!field.getType().equals(FieldType.GEOMETRY)) {

            Object value = feature.getValue(field);
            SimpleData simpleData = schemaData.createAndAddSimpleData(field.getName());
            simpleData.setValue(String.valueOf(value));
          }
        }
      }

      // En fonction dy type de géométrie Jts, appel
      // aux fonctions de conversion en géométries Kml

      // POINT
      if (geometry instanceof Point) {

        placemark.setGeometry(getAsKmlPoint((Point) geometry));

        // LINESTRING
      } else if (geometry instanceof LineString) {

        placemark.setGeometry(getAsKmlLineString((LineString) geometry));

        // POLYGON
      } else if (geometry instanceof Polygon) {

        placemark.setGeometry(getAsKmlPolygon((Polygon) geometry));

        // MULTIPOINT
      } else if (geometry instanceof MultiPoint) {

        de.micromata.opengis.kml.v_2_2_0.MultiGeometry kmlMultiGeometry =
            placemark.createAndSetMultiGeometry();
        for (int i = 0; i < geometry.getNumGeometries(); i++) {

          kmlMultiGeometry.addToGeometry(getAsKmlPoint((Point) ((Point) geometry).getGeometryN(i)));
        }
        // MULTILINESTRING
      } else if (geometry instanceof MultiLineString) {

        de.micromata.opengis.kml.v_2_2_0.MultiGeometry kmlMultiGeometry =
            placemark.createAndSetMultiGeometry();
        for (int i = 0; i < geometry.getNumGeometries(); i++) {

          kmlMultiGeometry.addToGeometry(
              getAsKmlLineString((LineString) ((MultiLineString) geometry).getGeometryN(i)));
        }
        // MULTIPOLYGON
      } else if (geometry instanceof MultiPolygon) {

        de.micromata.opengis.kml.v_2_2_0.MultiGeometry kmlMultiGeometry =
            placemark.createAndSetMultiGeometry();
        for (int i = 0; i < geometry.getNumGeometries(); i++) {

          kmlMultiGeometry.addToGeometry(
              getAsKmlPolygon((Polygon) ((MultiPolygon) geometry).getGeometryN(i)));
        }
        // GEOMETRYCOLLECTION
      } else if (geometry instanceof GeometryCollection) {

        de.micromata.opengis.kml.v_2_2_0.MultiGeometry kmlMultiGeometry =
            placemark.createAndSetMultiGeometry();
        for (int i = 0; i < geometry.getNumGeometries(); i++) {

          Geometry currentGeometry = geometry.getGeometryN(i);

          if (currentGeometry instanceof Point) {
            kmlMultiGeometry.addToGeometry(getAsKmlPoint((Point) currentGeometry));
          } else if (currentGeometry instanceof LineString) {
            kmlMultiGeometry.addToGeometry(getAsKmlLineString((LineString) currentGeometry));
          } else if (currentGeometry instanceof Polygon) {
            kmlMultiGeometry.addToGeometry(getAsKmlPolygon((Polygon) currentGeometry));
          } else if (currentGeometry instanceof MultiPoint) {

            for (int j = 0; j < currentGeometry.getNumGeometries(); j++) {
              kmlMultiGeometry.addToGeometry(
                  getAsKmlPoint((Point) ((Point) currentGeometry).getGeometryN(j)));
            }

          } else if (currentGeometry instanceof MultiLineString) {

            for (int j = 0; j < currentGeometry.getNumGeometries(); j++) {
              kmlMultiGeometry.addToGeometry(
                  getAsKmlLineString((LineString) ((LineString) currentGeometry).getGeometryN(j)));
            }

          } else if (currentGeometry instanceof MultiPolygon) {

            for (int j = 0; j < currentGeometry.getNumGeometries(); j++) {
              kmlMultiGeometry.addToGeometry(
                  getAsKmlPolygon((Polygon) ((Polygon) currentGeometry).getGeometryN(j)));
            }
          }
        }
      }
    }

    if (isServletOutput) {

      if (features.size() > 0) {
        kml.marshal();
        kml.marshal(writer);
      }

    } else {

      try {

        FileOutputStream fileOutputStream = new FileOutputStream(this.kmlFileName);
        kml.marshal();
        kml.marshal(fileOutputStream);
        fileOutputStream.close();

      } catch (FileNotFoundException e) {
        throw new KettleException("Error writing features to " + this.kmlFileName, e);
      } catch (IOException e) {
        throw new KettleException("Error writing features to " + this.kmlFileName, e);
      }
    }
  }
コード例 #30
0
 private void writeGeometryArray(Geometry geom, ValueSetter dest) {
   dest.setInt(geom.getNumGeometries());
   for (int i = 0; i < geom.getNumGeometries(); i++) {
     writeGeometry(geom.getGeometryN(i), dest);
   }
 }