コード例 #1
0
  /**
   * Returns a completed multi type.
   *
   * @param geometryFactory The factory this method should use to create the multi type.
   * @return Appropriate multi geometry type.
   */
  public Geometry create(GeometryFactory geometryFactory) {
    if (internalType.equals("Point")) {
      Point[] pointArray = geometryFactory.toPointArray(geometries);
      MultiPoint multiPoint = geometryFactory.createMultiPoint(pointArray);
      multiPoint.setUserData(getSRS());
      multiPoint.setSRID(getSRID());
      LOGGER.fine("created " + multiPoint);

      return multiPoint;
    } else if (internalType.equals("LineString")) {
      LineString[] lineStringArray = geometryFactory.toLineStringArray(geometries);
      MultiLineString multiLineString = geometryFactory.createMultiLineString(lineStringArray);
      multiLineString.setUserData(getSRS());
      multiLineString.setSRID(getSRID());
      LOGGER.fine("created " + multiLineString);

      return multiLineString;
    } else if (internalType.equals("Polygon")) {
      Polygon[] polygonArray = geometryFactory.toPolygonArray(geometries);
      MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygonArray);
      multiPolygon.setUserData(getSRS());
      multiPolygon.setSRID(getSRID());
      LOGGER.fine("created " + multiPolygon);

      return multiPolygon;
    } else {
      return null;
    }
  }
コード例 #2
0
  private Geometry parseGeometry(JsonNode root) {
    String typeName = root.get("type").asText();
    if (typeName.equals("Point")) {
      return gf.createPoint(parseCoordinate((ArrayNode) root.get("coordinates")));

    } else if (typeName.equals("MultiPoint")) {
      return gf.createMultiPoint(parseLineString(root.get("coordinates")));

    } else if (typeName.equals("LineString")) {
      return gf.createLineString(parseLineString(root.get("coordinates")));

    } else if (typeName.equals("MultiLineString")) {
      return gf.createMultiLineString(parseLineStrings(root.get("coordinates")));

    } else if (typeName.equals("Polygon")) {
      JsonNode arrayOfRings = root.get("coordinates");
      return parsePolygonCoordinates(arrayOfRings);

    } else if (typeName.equals("MultiPolygon")) {
      JsonNode arrayOfPolygons = root.get("coordinates");
      return gf.createMultiPolygon(parsePolygons(arrayOfPolygons));

    } else if (typeName.equals("GeometryCollection")) {
      return gf.createGeometryCollection(parseGeometries(root.get("geometries")));
    } else {
      throw new UnsupportedOperationException();
    }
  }
コード例 #3
0
 @Test
 public void multiPoint() throws Exception {
   MultiPoint multiPoint =
       gf.createMultiPoint(new Point[] {gf.createPoint(new Coordinate(1.2345678, 2.3456789))});
   assertRoundTrip(multiPoint);
   assertThat(
       toJson(multiPoint),
       equalTo("{\"type\":\"MultiPoint\",\"coordinates\":[[1.2345678,2.3456789]]}"));
 }
コード例 #4
0
 private MultiPoint readMultiPoint() throws IOException, ParseException {
   int numGeom = dis.readInt();
   Point[] geoms = new Point[numGeom];
   for (int i = 0; i < numGeom; i++) {
     Geometry g = readGeometry();
     if (!(g instanceof Point)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "MultiPoint");
     geoms[i] = (Point) g;
   }
   return factory.createMultiPoint(geoms);
 }
コード例 #5
0
ファイル: ValuesTest.java プロジェクト: JimmyFarcy/orbisgis
 /** We must be able to transform specialized collections to GeometryCollectionValues */
 @Test
 public void testGeometryCollectionConversions() throws Exception {
   Value val =
       ValueFactory.createValue(
           gf.createMultiPoint(
               new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(1, 2, 3)}));
   assertTrue(val instanceof DefaultMultiPointValue);
   Value val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
   val =
       ValueFactory.createValue(
           gf.createMultiLineString(
               new LineString[] {
                 gf.createLineString(
                     new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(4, 2, 3)}),
                 gf.createLineString(
                     new Coordinate[] {new Coordinate(5, 6, 9), new Coordinate(5, 7, 1)})
               }));
   assertTrue(val instanceof DefaultMultiLineStringValue);
   val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
   val =
       ValueFactory.createValue(
           gf.createMultiPolygon(
               new Polygon[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(0, 3, 0),
                           new Coordinate(9, 0, 0),
                           new Coordinate(8, 7, 0),
                           new Coordinate(0, 3, 0)
                         }),
                     null),
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(10, 3, 0),
                           new Coordinate(9, 0, 0),
                           new Coordinate(8, 7, 0),
                           new Coordinate(10, 3, 0)
                         }),
                     null)
               }));
   assertTrue(val instanceof DefaultMultiPolygonValue);
   val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
 }
コード例 #6
0
  public static void main(String[] args) {

    // Handle invalid arguments..
    if (args.length < 2) {
      System.out.println("Usage: ConvexHull arg1 arg2");
      System.out.println("arg1: input dataset A file path [points]");
      System.out.println("arg2: output file name and path");
      System.exit(1);
    }

    // Creating and setting sparkconf
    SparkConf sparkConf = new SparkConf().setAppName("Group3-edu.asu.cse512.ConvexHull");
    JavaSparkContext sc = new JavaSparkContext(sparkConf);

    // Adding external jars
    // sc.addJar("lib/jts-1.13.jar");

    JavaRDD<String> lines = sc.textFile(args[0]);
    // Using mapPartitions function to find convex hull points in distributed environment
    JavaRDD<Coordinate> hullPointsRDD = lines.mapPartitions(new ConvexH());
    List<Coordinate> hullPointsList = hullPointsRDD.collect();
    Coordinate[] inputArray = new Coordinate[hullPointsList.size()];
    int j = 0;
    for (Coordinate c : hullPointsList) {
      inputArray[j] = c;
      j++;
    }
    // Finding convex hull points on the final subset of points retrieved from distributed
    // environment
    GeometryFactory geoFactory1 = new GeometryFactory();
    MultiPoint mPoint1 = geoFactory1.createMultiPoint(inputArray);
    Geometry geo1 = mPoint1.convexHull();
    Coordinate[] convexHullResult = geo1.getCoordinates();
    int length = convexHullResult.length;
    Coordinate[] convexHullFinalResult = Arrays.copyOf(convexHullResult, length - 1);
    Arrays.sort(convexHullFinalResult);

    // Converting the list of coordinates into Coordinate RDD
    JavaRDD<Coordinate> convexHullResultRDD =
        sc.parallelize(Arrays.asList(convexHullFinalResult), 1);
    JavaRDD<String> convexHullResultString =
        convexHullResultRDD
            .repartition(1)
            .map(
                new Function<Coordinate, String>() {
                  public String call(Coordinate hullPoint) throws Exception {

                    return hullPoint.x + "," + hullPoint.y;
                  }
                });
    // Save the String RDD into text file. Using repartition(1) to preserve the order of coordinates
    convexHullResultString.repartition(1).saveAsTextFile(args[1]);
  }
コード例 #7
0
ファイル: ValuesTest.java プロジェクト: JimmyFarcy/orbisgis
  @Test
  public void test3DGeoms() throws Exception {
    Coordinate[] coords2D =
        new Coordinate[] {
          new Coordinate(10, 10, 10),
          new Coordinate(40, 10, 10),
          new Coordinate(40, 40, 10),
          new Coordinate(10, 40, 10),
          new Coordinate(10, 10, 10),
        };
    Coordinate[] coords3D =
        new Coordinate[] {
          new Coordinate(10, 10),
          new Coordinate(40, 10),
          new Coordinate(40, 40),
          new Coordinate(10, 40),
          new Coordinate(10, 10),
        };

    Value p1 = ValueFactory.createValue(gf.createPoint(new Coordinate(10, 10, 10)));
    Value p2 = ValueFactory.createValue(gf.createPoint(new Coordinate(10, 10)));
    checkDifferent(p1, p2);

    LineString l1 = gf.createLineString(coords2D);
    p1 = ValueFactory.createValue(l1);
    LineString l2 = gf.createLineString(coords3D);
    p2 = ValueFactory.createValue(l2);
    checkDifferent(p1, p2);

    p1 = ValueFactory.createValue(gf.createMultiPoint(coords2D));
    p2 = ValueFactory.createValue(gf.createMultiPoint(coords3D));
    checkDifferent(p1, p2);

    Polygon pol1 = gf.createPolygon(gf.createLinearRing(coords2D), null);
    p1 = ValueFactory.createValue(pol1);
    Polygon pol2 = gf.createPolygon(gf.createLinearRing(coords3D), null);
    p2 = ValueFactory.createValue(pol2);
    checkDifferent(p1, p2);

    p1 = ValueFactory.createValue(gf.createMultiLineString(new LineString[] {l1}));
    p2 = ValueFactory.createValue(gf.createMultiLineString(new LineString[] {l2}));
    checkDifferent(p1, p2);

    p1 = ValueFactory.createValue(gf.createMultiPolygon(new Polygon[] {pol1}));
    p2 = ValueFactory.createValue(gf.createMultiPolygon(new Polygon[] {pol2}));
    checkDifferent(p1, p2);
  }
コード例 #8
0
 public Object convert(Object obj) {
   GeometryFactory fac = new GeometryFactory();
   if (getBinding() == MultiPolygon.class && obj instanceof Polygon) {
     return fac.createMultiPolygon(new Polygon[] {(Polygon) obj});
   }
   if (getBinding() == MultiPoint.class && obj instanceof Point) {
     return fac.createMultiPoint(new Point[] {(Point) obj});
   }
   if (getBinding() == MultiLineString.class && obj instanceof LineString) {
     return fac.createMultiLineString(new LineString[] {(LineString) obj});
   }
   if (getBinding() == GeometryCollection.class && obj instanceof Geometry) {
     return fac.createGeometryCollection(
         new com.vividsolutions.jts.geom.Geometry[] {(com.vividsolutions.jts.geom.Geometry) obj});
   }
   return obj;
 }
コード例 #9
0
 public Geometry getGeometry() {
   int n = collection.size();
   if (MultiPolygon.class.isAssignableFrom(binding)) {
     Polygon[] array = new Polygon[n];
     for (int i = 0; i < n; i++) array[i] = (Polygon) collection.get(i);
     return factory.createMultiPolygon(array);
   }
   if (MultiLineString.class.isAssignableFrom(binding)) {
     LineString[] array = new LineString[n];
     for (int i = 0; i < n; i++) array[i] = (LineString) collection.get(i);
     return factory.createMultiLineString(array);
   }
   if (MultiPoint.class.isAssignableFrom(binding)) {
     Point[] array = new Point[n];
     for (int i = 0; i < n; i++) array[i] = (Point) collection.get(i);
     return factory.createMultiPoint(array);
   }
   return null;
 }
コード例 #10
0
  /**
   * Parses a MultiPoint.
   *
   * <p>Precondition: parser positioned at a {@link GML#MultiPoint MultiPoint} start tag
   *
   * <p>Postcondition: parser positioned at the {@link GML#MultiPoint MultiPoint} end tag of the
   * starting tag
   *
   * @throws IOException
   * @throws XmlPullParserException
   * @throws IOException
   * @throws XmlPullParserException
   * @throws FactoryException
   * @throws NoSuchAuthorityCodeException
   * @throws FactoryException
   * @throws NoSuchAuthorityCodeException
   */
  private Geometry parseMultiPoint(int dimension, CoordinateReferenceSystem crs)
      throws XmlPullParserException, IOException, NoSuchAuthorityCodeException, FactoryException {
    Geometry geom;
    parser.nextTag();
    final QName memberTag = new QName(parser.getNamespace(), parser.getName());
    List<Point> points = new ArrayList<Point>(4);
    if (GML.pointMembers.equals(memberTag)) {
      while (true) {
        parser.nextTag();
        if (END_TAG == parser.getEventType()
            && GML.pointMembers.getLocalPart().equals(parser.getName())) {
          // we're done
          break;
        }
        Point p = parsePoint(dimension, crs);
        points.add(p);
      }
      parser.nextTag();
    } else if (GML.pointMember.equals(memberTag)) {
      while (true) {
        parser.nextTag();
        parser.require(START_TAG, GML.NAMESPACE, GML.Point.getLocalPart());

        Point p = parsePoint(dimension, crs);
        points.add(p);
        parser.nextTag();
        parser.require(END_TAG, GML.NAMESPACE, GML.pointMember.getLocalPart());
        parser.nextTag();
        if (END_TAG == parser.getEventType()
            && GML.MultiPoint.getLocalPart().equals(parser.getName())) {
          // we're done
          break;
        }
      }
    }
    parser.require(END_TAG, GML.NAMESPACE, GML.MultiPoint.getLocalPart());

    geom = geomFac.createMultiPoint(points.toArray(new Point[points.size()]));
    return geom;
  }
コード例 #11
0
  public Iterable<Coordinate> call(Iterator<String> coordinatesIterator) throws Exception {
    // TODO Auto-generated method stub
    List<Coordinate> coorList = new ArrayList<Coordinate>();

    // Retrieving points from JavaRDD<String> and storing it in a list
    while (coordinatesIterator.hasNext()) {
      String[] temp = coordinatesIterator.next().split(",");
      coorList.add(new Coordinate(Double.parseDouble(temp[0]), Double.parseDouble(temp[1])));
    }
    Coordinate[] coorArray = new Coordinate[coorList.size()];
    int i = 0;
    for (Coordinate c : coorList) {
      coorArray[i] = c;
      i++;
    }
    // Using Geometry class of JTS library to find convex hull points
    GeometryFactory geoFactory = new GeometryFactory();
    MultiPoint mPoint = geoFactory.createMultiPoint(coorArray);
    Geometry geo = mPoint.convexHull();
    Coordinate[] convexResult = geo.getCoordinates();
    return Arrays.asList(convexResult);
  }
  private void calculateVector() {
    /*
     * Notice that this tool assumes that each record in the shapefile is an
     * individual polygon. The feature can contain multiple parts only if it
     * has holes, i.e. islands. A multipart record cannot contain multiple
     * and seperate features. This is because it complicates the calculation
     * of feature area and perimeter.
     */

    amIActive = true;

    // Declare the variable.
    String inputFile = null;
    int progress;
    double featureArea = 0;
    double circleArea = 0;
    double radius = 0;
    int recNum;
    int j, i;
    double[][] vertices = null;
    CoordinateArraySequence coordArray;
    LinearRing ring;
    MinimumBoundingCircle mbc;
    GeometryFactory factory = new GeometryFactory();
    Geometry geom;

    if (args.length <= 0) {
      showFeedback("Plugin parameters have not been set.");
      return;
    }

    inputFile = args[0];
    /*
     * args[1], args[2], and args[3] are ignored by the vector tool
     */

    // check to see that the inputHeader and outputHeader are not null.
    if (inputFile == null) {
      showFeedback("One or more of the input parameters have not been set properly.");
      return;
    }

    try {

      ShapeFile input = new ShapeFile(inputFile);
      double numberOfRecords = input.getNumberOfRecords();

      if (input.getShapeType().getBaseType() != ShapeType.POLYGON) {
        showFeedback("This function can only be applied to polygon type shapefiles.");
        return;
      }

      /* create a new field in the input file's database
      to hold the fractal dimension. Put it at the end
      of the database. */
      DBFField field = new DBFField();
      field = new DBFField();
      field.setName("RC_CIRCLE");
      field.setDataType(DBFField.DBFDataType.NUMERIC);
      field.setFieldLength(10);
      field.setDecimalCount(4);
      input.getAttributeTable().addField(field);

      // initialize the shapefile.
      ShapeType inputType = input.getShapeType();

      for (ShapeFileRecord record : input.records) {
        switch (inputType) {
          case POLYGON:
            whitebox.geospatialfiles.shapefile.Polygon recPolygon =
                (whitebox.geospatialfiles.shapefile.Polygon) (record.getGeometry());
            vertices = recPolygon.getPoints();
            coordArray = new CoordinateArraySequence(vertices.length);
            j = 0;
            for (i = 0; i < vertices.length; i++) {
              coordArray.setOrdinate(j, 0, vertices[i][0]);
              coordArray.setOrdinate(j, 1, vertices[i][1]);
              j++;
            }
            geom = factory.createMultiPoint(coordArray);
            mbc = new MinimumBoundingCircle(geom);
            radius = mbc.getRadius();
            circleArea = Math.PI * radius * radius;
            featureArea = recPolygon.getArea();
            break;
          case POLYGONZ:
            PolygonZ recPolygonZ = (PolygonZ) (record.getGeometry());
            vertices = recPolygonZ.getPoints();
            coordArray = new CoordinateArraySequence(vertices.length);
            j = 0;
            for (i = 0; i < vertices.length; i++) {
              coordArray.setOrdinate(j, 0, vertices[i][0]);
              coordArray.setOrdinate(j, 1, vertices[i][1]);
              j++;
            }
            geom = factory.createMultiPoint(coordArray);
            mbc = new MinimumBoundingCircle(geom);
            radius = mbc.getRadius();
            circleArea = Math.PI * radius * radius;
            featureArea = recPolygonZ.getArea();
            break;
          case POLYGONM:
            PolygonM recPolygonM = (PolygonM) (record.getGeometry());
            vertices = recPolygonM.getPoints();
            coordArray = new CoordinateArraySequence(vertices.length);
            j = 0;
            for (i = 0; i < vertices.length; i++) {
              coordArray.setOrdinate(j, 0, vertices[i][0]);
              coordArray.setOrdinate(j, 1, vertices[i][1]);
              j++;
            }
            geom = factory.createMultiPoint(coordArray);
            mbc = new MinimumBoundingCircle(geom);
            radius = mbc.getRadius();
            circleArea = Math.PI * radius * radius;
            featureArea = recPolygonM.getArea();
            break;
        }

        recNum = record.getRecordNumber() - 1;
        Object[] recData = input.getAttributeTable().getRecord(recNum);
        if (circleArea > 0) {
          recData[recData.length - 1] = new Double(1 - featureArea / circleArea);
        } else {
          recData[recData.length - 1] = new Double(0);
        }
        input.getAttributeTable().updateRecord(recNum, recData);

        if (cancelOp) {
          cancelOperation();
          return;
        }
        progress = (int) (record.getRecordNumber() / numberOfRecords * 100);
        updateProgress(progress);
      }

      // returning the database file will result in it being opened in the Whitebox GUI.
      returnData(input.getDatabaseFile());

    } catch (OutOfMemoryError oe) {
      myHost.showFeedback("An out-of-memory error has occurred during operation.");
    } catch (Exception e) {
      myHost.showFeedback("An error has occurred during operation. See log file for details.");
      myHost.logException("Error in " + getDescriptiveName(), e);
    } finally {
      updateProgress("Progress: ", 0);
      // tells the main application that this process is completed.
      amIActive = false;
      myHost.pluginComplete();
    }
  }
コード例 #13
0
 static MultiPoint multiPoint() {
   return gf.createMultiPoint(new Coordinate[] {new Coordinate(1, 1), new Coordinate(2, 2)});
 }
コード例 #14
0
  /**
   * Calculates walksheds for a given location, based on time given to walk and the walk speed.
   *
   * <p>Depending on the value for the "output" parameter (i.e. "POINTS", "SHED" or "EDGES"), a
   * different type of GeoJSON geometry is returned. If a SHED is requested, then a ConcaveHull of
   * the EDGES/roads is returned. If that fails, a ConvexHull will be returned.
   *
   * <p>The ConcaveHull parameter is set to 0.005 degrees. The offroad walkspeed is assumed to be
   * 0.83333 m/sec (= 3km/h) until a road is hit.
   *
   * <p>Note that the set of EDGES/roads returned as well as POINTS returned may contain duplicates.
   * If POINTS are requested, then not the end-points are returned at which the max time is reached,
   * but instead all the graph nodes/crossings that are within the time limits.
   *
   * <p>In case there is no road near by within the given time, then a circle for the walktime limit
   * is created and returned for the SHED parameter. Otherwise the edge with the direction towards
   * the closest road. Note that the circle is calculated in Euclidian 2D coordinates, and
   * distortions towards an ellipse will appear if it is transformed/projected to the user location.
   *
   * <p>An example request may look like this:
   * localhost:8080/otp-rest-servlet/ws/iso?layers=traveltime&styles=mask&batch=true&fromPlace=51.040193121307176
   * %2C-114.04471635818481&toPlace
   * =51.09098935%2C-113.95179705&time=2012-06-06T08%3A00%3A00&mode=WALK&maxWalkDistance=10000&walkSpeed=1.38&walkTime=10.7&output=EDGES
   * Though the first parameters (i) layer, (ii) styles and (iii) batch could be discarded.
   *
   * @param walkmins Maximum number of minutes to walk.
   * @param output Can be set to "POINTS", "SHED" or "EDGES" to return different types of GeoJSON
   *     geometry. SHED returns a ConcaveHull or ConvexHull of the edges/roads. POINTS returns all
   *     graph nodes that are within the time limit.
   * @return a JSON document containing geometries (either points, lineStrings or a polygon).
   * @throws Exception
   * @author sstein---geo.uzh.ch
   */
  @GET
  @Produces({MediaType.APPLICATION_JSON})
  public String getIsochrone(
      @QueryParam("walkTime") @DefaultValue("15") double walkmins,
      @QueryParam("output") @DefaultValue("POINTS") String output)
      throws Exception {

    this.debugGeoms = new ArrayList();
    this.tooFastTraversedEdgeGeoms = new ArrayList();

    RoutingRequest sptRequestA = buildRequest(0);
    String from = sptRequestA.getFrom().toString();
    int pos = 1;
    float lat = 0;
    float lon = 0;
    for (String s : from.split(",")) {
      if (s.isEmpty()) {
        // no location
        Response.status(Status.BAD_REQUEST).entity("no position").build();
        return null;
      }
      try {
        float num = Float.parseFloat(s);
        if (pos == 1) {
          lat = num;
        }
        if (pos == 2) {
          lon = num;
        }
      } catch (Exception e) {
        throw new WebApplicationException(
            Response.status(Status.BAD_REQUEST)
                .entity(
                    "Could not parse position string to number. Require numerical lat & long coords.")
                .build());
      }
      pos++;
    }

    GeometryFactory gf = new GeometryFactory();

    Coordinate dropPoint = new Coordinate(lon, lat);

    int walkInMin = (int) Math.floor(walkmins);
    double walkInSec = walkmins * 60;
    LOG.debug(
        "given travel time: " + walkInMin + " mins + " + (walkInSec - (60 * walkInMin)) + " sec");
    // restrict the evaluated SPT size to 30mins for requests with walking < 30min
    // if larger walking times are requested we adjust the evaluated
    // graph dynamically by 1.3 * min -> this should save processing time
    if (walkInMin < 30) {
      sptRequestA.worstTime = sptRequestA.dateTime + (30 * 60);
    } else {
      sptRequestA.worstTime = sptRequestA.dateTime + Math.round(walkInMin * 1.3 * 60);
    }
    // set the switch-time for shed/area calculation, i.e. to decide if the hull is calculated based
    // on points or on edges
    TraverseModeSet modes = sptRequestA.modes;
    LOG.debug("mode(s): " + modes);
    if ((modes.contains(TraverseMode.TRANSIT))
        || (modes.contains(TraverseMode.BUSISH))
        || (modes.contains(TraverseMode.TRAINISH))) {
      shedCalcMethodSwitchTimeInSec =
          60 * 20; // 20min (use 20min for transit, since buses may not come all the time)
    } else if (modes.contains(TraverseMode.CAR)) {
      shedCalcMethodSwitchTimeInSec = 60 * 10; // 10min
    } else if (modes.contains(TraverseMode.BICYCLE)) {
      shedCalcMethodSwitchTimeInSec = 60 * 10; // 10min
    } else {
      shedCalcMethodSwitchTimeInSec = 60 * 20; // 20min
    }
    // set the maxUserSpeed, which is used later to check for u-type streets/crescents when
    // calculating sub-edges;
    // Note, that the car speed depends on the edge itself, so this value may be replaced later
    this.usesCar = false;
    int numberOfModes = modes.getModes().size();
    if (numberOfModes == 1) {
      if (modes.getWalk()) {
        this.maxUserSpeed = sptRequestA.getWalkSpeed();
      } else if (modes.getBicycle()) {
        this.maxUserSpeed = sptRequestA.getBikeSpeed();
      } else if (modes.getDriving()) {
        this.maxUserSpeed = sptRequestA.getCarSpeed();
        this.usesCar = true;
      }
    } else { // for all other cases (multiple-modes)
      // sstein: I thought I may set it to 36.111 m/sec = 130 km/h,
      // but maybe it is better to assume walk speed for transit, i.e. treat it like if the
      // person gets off the bus on the last crossing and walks the "last mile".
      this.maxUserSpeed = sptRequestA.getWalkSpeed();
    }

    if (doSpeedTest) {
      LOG.debug("performing angle and speed based test to detect u-shapes");
    } else {
      LOG.debug("performing only angle based test to detect u-shapes");
    }

    // TODO: OTP prefers to snap to car-roads/ways, which is not so nice, when walking,
    // and a footpath is closer by. So far there is no option to switch that off

    // create the ShortestPathTree
    try {
      sptRequestA.setRoutingContext(graphService.getGraph());
    } catch (Exception e) {
      // if we get an exception here, and in particular a VertexNotFoundException,
      // then it is likely that we chose a (transit) mode without having that (transit) modes data
      LOG.debug("cannot set RoutingContext: " + e.toString());
      LOG.debug("cannot set RoutingContext: setting mode=WALK");
      sptRequestA.setMode(TraverseMode.WALK); // fall back to walk mode
      sptRequestA.setRoutingContext(graphService.getGraph());
    }
    ShortestPathTree sptA = sptService.getShortestPathTree(sptRequestA);
    StreetLocation origin = (StreetLocation) sptRequestA.rctx.fromVertex;
    sptRequestA.cleanup(); // remove inserted points

    // create a LineString for display
    Coordinate pathToStreetCoords[] = new Coordinate[2];
    pathToStreetCoords[0] = dropPoint;
    pathToStreetCoords[1] = origin.getCoordinate();
    LineString pathToStreet = gf.createLineString(pathToStreetCoords);

    // get distance between origin and drop point for time correction
    double distanceToRoad =
        this.distanceLibrary.distance(origin.getY(), origin.getX(), dropPoint.y, dropPoint.x);
    long offRoadTimeCorrection = (long) (distanceToRoad / this.offRoadWalkspeed);

    //
    // --- filter the states ---
    //
    Set<Coordinate> visitedCoords = new HashSet<Coordinate>();
    ArrayList<Edge> allConnectingEdges = new ArrayList<Edge>();
    Coordinate coords[] = null;
    long maxTime = (long) walkInSec - offRoadTimeCorrection;
    // System.out.println("Reducing walktime from: " + (int)(walkmins * 60) + "sec to " + maxTime +
    // "sec due to initial walk of " + distanceToRoad
    // + "m");

    // if the initial walk is already to long, there is no need to parse...
    if (maxTime <= 0) {
      noRoadNearBy = true;
      long timeToWalk = (long) walkInSec;
      long timeBetweenStates = offRoadTimeCorrection;
      long timeMissing = timeToWalk;
      double fraction = (double) timeMissing / (double) timeBetweenStates;
      pathToStreet = getSubLineString(pathToStreet, fraction);
      LOG.debug(
          "no street found within giving travel time (for off-road walkspeed: {} m/sec)",
          this.offRoadWalkspeed);
    } else {
      noRoadNearBy = false;
      Map<ReversibleLineStringWrapper, Edge> connectingEdgesMap = Maps.newHashMap();
      for (State state : sptA.getAllStates()) {
        long et = state.getElapsedTimeSeconds();
        if (et <= maxTime) {
          // -- filter points, as the same coordinate may be passed several times due to the graph
          // structure
          // in a Calgary suburb family homes neighborhood with a 15min walkshed it filtered about
          // 250 points away (while 145 were finally displayed)
          if (visitedCoords.contains(state.getVertex().getCoordinate())) {
            continue;
          } else {
            visitedCoords.add(state.getVertex().getCoordinate());
          }
          // -- get all Edges needed later for the edge representation
          // and to calculate an edge-based walkshed
          // Note, it can happen that we get a null geometry here, e.g. for hop-edges!
          Collection<Edge> vertexEdgesIn = state.getVertex().getIncoming();
          for (Iterator<Edge> iterator = vertexEdgesIn.iterator(); iterator.hasNext(); ) {
            Edge edge = (Edge) iterator.next();
            Geometry edgeGeom = edge.getGeometry();
            if (edgeGeom != null) { // make sure we get only real edges
              if (edgeGeom instanceof LineString) {
                // allConnectingEdges.add(edge); // instead of this, use a map now, so we don't have
                // similar edge many times
                connectingEdgesMap.put(
                    new ReversibleLineStringWrapper((LineString) edgeGeom), edge);
              }
            }
          }
          Collection<Edge> vertexEdgesOut = state.getVertex().getOutgoing();
          for (Iterator<Edge> iterator = vertexEdgesOut.iterator(); iterator.hasNext(); ) {
            Edge edge = (Edge) iterator.next();
            Geometry edgeGeom = edge.getGeometry();
            if (edgeGeom != null) {
              if (edgeGeom instanceof LineString) {
                // allConnectingEdges.add(edge); // instead of this, use a map now, so we don't
                // similar edge many times
                connectingEdgesMap.put(
                    new ReversibleLineStringWrapper((LineString) edgeGeom), edge);
              }
            }
          }
        } // end : if(et < maxTime)
      }
      // --
      // points from list to array, for later
      coords = new Coordinate[visitedCoords.size()];
      int i = 0;
      for (Coordinate c : visitedCoords) coords[i++] = c;

      // connection edges from Map to List
      allConnectingEdges.clear();
      for (Edge tedge : connectingEdgesMap.values()) allConnectingEdges.add(tedge);
    }
    StringWriter sw = new StringWriter();
    GeoJSONBuilder json = new GeoJSONBuilder(sw);
    //
    // -- create the different outputs ---
    //
    try {
      if (output.equals(IsoChrone.RESULT_TYPE_POINTS)) {
        // in case there was no road we create a circle and
        // and return those points
        if (noRoadNearBy) {
          Geometry circleShape = createCirle(dropPoint, pathToStreet);
          coords = circleShape.getCoordinates();
        }
        // -- the states/nodes with time elapsed <= X min.
        LOG.debug("write multipoint geom with {} points", coords.length);
        json.writeGeom(gf.createMultiPoint(coords));
        LOG.debug("done");
      } else if (output.equals(IsoChrone.RESULT_TYPE_SHED)) {

        Geometry geomsArray[] = null;
        // in case there was no road we create a circle
        if (noRoadNearBy) {
          Geometry circleShape = createCirle(dropPoint, pathToStreet);
          json.writeGeom(circleShape);
        } else {
          if (maxTime > shedCalcMethodSwitchTimeInSec) { // eg., walkshed > 20 min
            // -- create a point-based walkshed
            // less exact and should be used for large walksheds with many edges
            LOG.debug("create point-based shed (not from edges)");
            geomsArray = new Geometry[coords.length];
            for (int j = 0; j < geomsArray.length; j++) {
              geomsArray[j] = gf.createPoint(coords[j]);
            }
          } else {
            // -- create an edge-based walkshed
            // it is more exact and should be used for short walks
            LOG.debug("create edge-based shed (not from points)");
            Map<ReversibleLineStringWrapper, LineString> walkShedEdges = Maps.newHashMap();
            // add the walk from the pushpin to closest street point
            walkShedEdges.put(new ReversibleLineStringWrapper(pathToStreet), pathToStreet);
            // get the edges and edge parts within time limits
            ArrayList<LineString> withinTimeEdges =
                this.getLinesAndSubEdgesWithinMaxTime(
                    maxTime,
                    allConnectingEdges,
                    sptA,
                    angleLimitForUShapeDetection,
                    distanceToleranceForUShapeDetection,
                    maxUserSpeed,
                    usesCar,
                    doSpeedTest);
            for (LineString ls : withinTimeEdges) {
              walkShedEdges.put(new ReversibleLineStringWrapper(ls), ls);
            }
            geomsArray = new Geometry[walkShedEdges.size()];
            int k = 0;
            for (LineString ls : walkShedEdges.values()) geomsArray[k++] = ls;
          } // end if-else: maxTime condition
          GeometryCollection gc = gf.createGeometryCollection(geomsArray);
          // create the concave hull, but in case it fails we just return the convex hull
          Geometry outputHull = null;
          LOG.debug(
              "create concave hull from {} geoms with edge length limit of about {} m (distance on meridian)",
              geomsArray.length,
              concaveHullAlpha * 111132);
          // 1deg at Latitude phi = 45deg is about 111.132km
          // (see wikipedia:
          // http://en.wikipedia.org/wiki/Latitude#The_length_of_a_degree_of_latitude)
          try {
            ConcaveHull hull = new ConcaveHull(gc, concaveHullAlpha);
            outputHull = hull.getConcaveHull();
          } catch (Exception e) {
            outputHull = gc.convexHull();
            LOG.debug("Could not generate ConcaveHull for WalkShed, using ConvexHull instead.");
          }
          LOG.debug("write shed geom");
          json.writeGeom(outputHull);
          LOG.debug("done");
        }
      } else if (output.equals(IsoChrone.RESULT_TYPE_EDGES)) {
        // in case there was no road we return only the suggested path to the street
        if (noRoadNearBy) {
          json.writeGeom(pathToStreet);
        } else {
          // -- if we would use only the edges from the paths to the origin we will miss
          // some edges that will be never on the shortest path (e.g. loops/crescents).
          // However, we can retrieve all edges by checking the times for each
          // edge end-point
          Map<ReversibleLineStringWrapper, LineString> walkShedEdges = Maps.newHashMap();
          // add the walk from the pushpin to closest street point
          walkShedEdges.put(new ReversibleLineStringWrapper(pathToStreet), pathToStreet);
          // get the edges and edge parts within time limits
          ArrayList<LineString> withinTimeEdges =
              this.getLinesAndSubEdgesWithinMaxTime(
                  maxTime,
                  allConnectingEdges,
                  sptA,
                  angleLimitForUShapeDetection,
                  distanceToleranceForUShapeDetection,
                  maxUserSpeed,
                  usesCar,
                  doSpeedTest);
          for (LineString ls : withinTimeEdges) {
            walkShedEdges.put(new ReversibleLineStringWrapper(ls), ls);
          }
          Geometry mls = null;
          LineString edges[] = new LineString[walkShedEdges.size()];
          int k = 0;
          for (LineString ls : walkShedEdges.values()) edges[k++] = ls;
          LOG.debug("create multilinestring from {} geoms", edges.length);
          mls = gf.createMultiLineString(edges);
          LOG.debug("write geom");
          json.writeGeom(mls);
          LOG.debug("done");
        }
      } else if (output.equals("DEBUGEDGES")) {
        // -- for debugging, i.e. display of detected u-shapes/crescents
        ArrayList<LineString> withinTimeEdges =
            this.getLinesAndSubEdgesWithinMaxTime(
                maxTime,
                allConnectingEdges,
                sptA,
                angleLimitForUShapeDetection,
                distanceToleranceForUShapeDetection,
                maxUserSpeed,
                usesCar,
                doSpeedTest);
        if (this.showTooFastEdgesAsDebugGeomsANDnotUShapes) {
          LOG.debug("displaying edges that are traversed too fast");
          this.debugGeoms = this.tooFastTraversedEdgeGeoms;
        } else {
          LOG.debug("displaying detected u-shaped roads/crescents");
        }
        LineString edges[] = new LineString[this.debugGeoms.size()];
        int k = 0;
        for (Iterator iterator = debugGeoms.iterator(); iterator.hasNext(); ) {
          LineString ls = (LineString) iterator.next();
          edges[k] = ls;
          k++;
        }
        Geometry mls = gf.createMultiLineString(edges);
        LOG.debug("write debug geom");
        json.writeGeom(mls);
        LOG.debug("done");
      }
    } catch (org.codehaus.jettison.json.JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return sw.toString();
  }
コード例 #15
0
  /**
   * Returns a non-null default value for the class that is passed in. This is a helper class an
   * can't create a default class for any type but it does support:
   *
   * <ul>
   *   <li>String
   *   <li>Object - will return empty string
   *   <li>Number
   *   <li>Character
   *   <li>JTS Geometries
   * </ul>
   *
   * @param type
   * @return
   */
  public static Object defaultValue(Class type) {
    if (type == String.class || type == Object.class) {
      return "";
    }
    if (type == Integer.class) {
      return new Integer(0);
    }
    if (type == Double.class) {
      return new Double(0);
    }
    if (type == Long.class) {
      return new Long(0);
    }
    if (type == Short.class) {
      return new Short((short) 0);
    }
    if (type == Float.class) {
      return new Float(0.0f);
    }
    if (type == BigDecimal.class) {
      return BigDecimal.valueOf(0);
    }
    if (type == BigInteger.class) {
      return BigInteger.valueOf(0);
    }
    if (type == Character.class) {
      return new Character(' ');
    }
    if (type == Boolean.class) {
      return Boolean.FALSE;
    }
    if (type == Timestamp.class) return new Timestamp(System.currentTimeMillis());
    if (type == java.sql.Date.class) return new java.sql.Date(System.currentTimeMillis());
    if (type == java.sql.Time.class) return new java.sql.Time(System.currentTimeMillis());
    if (type == java.util.Date.class) return new java.util.Date();

    GeometryFactory fac = new GeometryFactory();
    Coordinate coordinate = new Coordinate(0, 0);
    Point point = fac.createPoint(coordinate);

    if (type == Point.class) {
      return point;
    }
    if (type == MultiPoint.class) {
      return fac.createMultiPoint(new Point[] {point});
    }
    if (type == LineString.class) {
      return fac.createLineString(
          new Coordinate[] {coordinate, coordinate, coordinate, coordinate});
    }
    LinearRing linearRing =
        fac.createLinearRing(new Coordinate[] {coordinate, coordinate, coordinate, coordinate});
    if (type == LinearRing.class) {
      return linearRing;
    }
    if (type == MultiLineString.class) {
      return fac.createMultiLineString(new LineString[] {linearRing});
    }
    Polygon polygon = fac.createPolygon(linearRing, new LinearRing[0]);
    if (type == Polygon.class) {
      return polygon;
    }
    if (type == MultiPolygon.class) {
      return fac.createMultiPolygon(new Polygon[] {polygon});
    }

    throw new IllegalArgumentException(type + " is not supported by this method");
  }
コード例 #16
0
ファイル: GeometryHandler.java プロジェクト: jdeolive/jeo
 MultiPoint createMultiPoint(List list) {
   return gf.createMultiPoint(coordseq(list));
 }
コード例 #17
0
ファイル: ValuesTest.java プロジェクト: JimmyFarcy/orbisgis
 @Test
 public void testGeometryType() throws Exception {
   // We test the point
   Value val = ValueFactory.createValue(gf.createPoint(new Coordinate(2, 1)));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.POINT);
   // We test the multipoint
   val = ValueFactory.createValue(gf.createMultiPoint(new Coordinate[] {new Coordinate(2, 1)}));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.MULTIPOINT);
   // We test the LineString
   val =
       ValueFactory.createValue(
           gf.createLineString(new Coordinate[] {new Coordinate(2, 1), new Coordinate(2, 2)}));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.LINESTRING);
   // We test the MultiLineString
   val =
       ValueFactory.createValue(
           gf.createMultiLineString(
               new LineString[] {
                 gf.createLineString(new Coordinate[] {new Coordinate(2, 1), new Coordinate(2, 2)})
               }));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.MULTILINESTRING);
   // We test the Polygon
   val =
       ValueFactory.createValue(
           gf.createPolygon(
               gf.createLinearRing(
                   new Coordinate[] {
                     new Coordinate(2, 1),
                     new Coordinate(2, 2),
                     new Coordinate(4, 3),
                     new Coordinate(2, 1)
                   }),
               null));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.POLYGON);
   // We test the MultiPolygon
   val =
       ValueFactory.createValue(
           gf.createMultiPolygon(
               new Polygon[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(2, 1),
                           new Coordinate(2, 2),
                           new Coordinate(4, 3),
                           new Coordinate(2, 1)
                         }),
                     null),
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(2, 1),
                           new Coordinate(2, 2),
                           new Coordinate(6, 3),
                           new Coordinate(2, 1)
                         }),
                     null)
               }));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.MULTIPOLYGON);
   // We test the GeometryCollection
   val =
       ValueFactory.createValue(
           gf.createGeometryCollection(
               new Geometry[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(2, 1),
                           new Coordinate(2, 2),
                           new Coordinate(4, 3),
                           new Coordinate(2, 1)
                         }),
                     null),
                 gf.createPoint(new Coordinate(2, 1))
               }));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue((val.getType() & Type.GEOMETRYCOLLECTION) != 0);
 }
コード例 #18
0
  @Test
  public void testSetup() throws Exception {
    EventListener l = new EventListener();
    EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    assertPixMapState(map, 1, 0, 0, 0);

    map.addPoint(10, 5, map.getGeoms().get(0).getShell());
    assertPixMapState(map, 1, 1, 0, 0);
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(5, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(EventType.ADD_POINT, l.event.getType());
    EditBlackboardEvent editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(null, editBlackboardEvent.getOldValue());
    assertEquals(Point.valueOf(10, 5), editBlackboardEvent.getNewValue());
    assertEquals(map.getGeoms().get(0).getShell(), editBlackboardEvent.getSource());

    map.addPoint(10, 10, map.getGeoms().get(0).getShell());

    assertPixMapState(map, 1, 2, 0, 0);
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY());
    assertEquals(EventType.ADD_POINT, l.event.getType());
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(null, editBlackboardEvent.getOldValue());
    assertEquals(Point.valueOf(10, 10), editBlackboardEvent.getNewValue());
    assertEquals(map.getGeoms().get(0).getShell(), editBlackboardEvent.getSource());

    GeometryFactory factory = new GeometryFactory();
    Geometry geom = factory.createPoint(new Coordinate(10, 5));
    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    Map<Geometry, EditGeom> mapping = map.setGeometries(geom, null);
    assertNotNull(mapping.get(geom));
    assertEquals(ShapeType.POINT, mapping.get(geom).getShapeType());
    assertPixMapState(map, 1, 1, 0, 0);
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(EventType.SET_GEOMS, l.event.getType());
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(1, ((List) editBlackboardEvent.getOldValue()).size());
    assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    geom =
        factory.createMultiPoint(new Coordinate[] {new Coordinate(10, 5), new Coordinate(20, 10)});
    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    String string = "featureID"; // $NON-NLS-1$
    mapping = map.setGeometries(geom, string);
    EditGeom next = mapping.values().iterator().next();
    assertEquals(ShapeType.POINT, next.getShapeType());
    assertEquals(string, next.getFeatureIDRef().get());
    assertNotNull(mapping.get(geom.getGeometryN(0)));
    assertNotNull(mapping.get(geom.getGeometryN(1)));
    assertPixMapState(map, 2, 1, 0, 0);
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(30, map.getGeoms().get(1).getShell().getPoint(0).getX());
    assertEquals(15, map.getGeoms().get(1).getShell().getPoint(0).getY());
    assertEquals(new Coordinate(10, 5), map.getGeoms().get(0).getShell().getCoord(0));
    assertEquals(new Coordinate(20, 10), map.getGeoms().get(1).getShell().getCoord(0));
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(2, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    LinearRing ring = createShellRing(factory, 10);

    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    mapping = map.setGeometries(ring, null);
    assertEquals(ShapeType.LINE, mapping.get(ring).getShapeType());
    assertNotNull(mapping.get(ring));
    assertPixMapState(map, 1, 5, 0, 0);
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(30, map.getGeoms().get(0).getShell().getPoint(1).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY());
    assertEquals(30, map.getGeoms().get(0).getShell().getPoint(2).getX());
    assertEquals(15, map.getGeoms().get(0).getShell().getPoint(2).getY());
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(3).getX());
    assertEquals(15, map.getGeoms().get(0).getShell().getPoint(3).getY());
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(4).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(4).getY());
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    Polygon polygon = createPolygon(factory, 10);
    mapping = map.setGeometries(polygon, null);
    assertEquals(ShapeType.POLYGON, mapping.get(polygon).getShapeType());
    assertNotNull(mapping.get(polygon));
    assertPixMapState(map, 1, 5, 1, 5);
    assertEquals(Point.valueOf(20, 10), map.getGeoms().get(0).getShell().getPoint(0));
    assertEquals(Point.valueOf(25, 12), map.getGeoms().get(0).getHoles().get(0).getPoint(0));
    assertEquals(Point.valueOf(30, 10), map.getGeoms().get(0).getShell().getPoint(1));
    assertEquals(Point.valueOf(28, 12), map.getGeoms().get(0).getHoles().get(0).getPoint(1));
    assertEquals(new Coordinate(15, 7), map.getGeoms().get(0).getHoles().get(0).getCoord(0));
    assertEquals(new Coordinate(18, 7), map.getGeoms().get(0).getHoles().get(0).getCoord(1));
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    geom =
        factory.createMultiPolygon(
            new Polygon[] {createPolygon(factory, 0), createPolygon(factory, 20)});

    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    mapping = map.setGeometries(geom, null);
    assertPixMapState(map, 2, 5, 1, 5);
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(2, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());
  }
コード例 #19
0
ファイル: Geometries.java プロジェクト: JimmyFarcy/orbisgis
 public static Geometry getMultiPoint3D() {
   Point[] points = new Point[2];
   points[0] = getPoint3D();
   points[1] = gf.createPoint(new Coordinate(23, 325, 74));
   return gf.createMultiPoint(points);
 }
コード例 #20
0
 protected MultiPoint decodeMultiPoint(JsonNode node, GeometryFactory fac)
     throws GeoJSONException {
   Coordinate[] coordinates = decodeCoordinates(requireCoordinates(node));
   return fac.createMultiPoint(coordinates);
 }