org.geomajas.geometry.Geometry类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(13.5k)|赞(0)|评价(0)|浏览(231)

本文整理了Java中org.geomajas.geometry.Geometry类的一些代码示例,展示了Geometry类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry类的具体详情如下:
包路径:org.geomajas.geometry.Geometry
类名称:Geometry

Geometry介绍

暂无

代码示例

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-impl

private Geometry screenToWorld(Geometry geometry) {
  if (geometry != null) {
    Geometry result = new Geometry(geometry.getGeometryType(), geometry.getSrid(), geometry.getPrecision());
    if (geometry.getGeometries() != null) {
      Geometry[] transformed = new Geometry[geometry.getGeometries().length];
      for (int i = 0; i < geometry.getGeometries().length; i++) {
        transformed[i] = screenToWorld(geometry.getGeometries()[i]);
      }
      result.setGeometries(transformed);
    }
    if (geometry.getCoordinates() != null) {
      Coordinate[] transformed = new Coordinate[geometry.getCoordinates().length];
      for (int i = 0; i < geometry.getCoordinates().length; i++) {
        transformed[i] = screenToWorld(geometry.getCoordinates()[i]);
      }
      result.setCoordinates(transformed);
    }
    return result;
  }
  throw new IllegalArgumentException("Cannot transform null geometry.");
}

代码示例来源:origin: org.geomajas/geomajas-gwt-client-impl

private void setMultiLineString(Geometry multiLineString) {
  if (multiLineString.getGeometries() != null && multiLineString.getGeometries().length > 0) {
    setLineString(multiLineString.getGeometries()[0]);
    for (int i = 1; i < multiLineString.getGeometries().length; i++) {
      Geometry lineString = multiLineString.getGeometries()[i];
      addSubPath(clone(lineString.getCoordinates()), false);
    }
  }
}

代码示例来源:origin: org.geomajas.plugin/geomajas-client-gwt2-plugin-editing-example-jar

@UiHandler("editBtn")
protected void onEditButtonClicked(ClickEvent event) {
  // Create a point geometry in the center of the map:
  Geometry point = new Geometry(Geometry.POINT, 0, -1);
  point.setCoordinates(new Coordinate[] { mapPresenter.getViewPort().getPosition() });
  // Now start editing it:
  editService.start(point);
}

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-example-jar

@UiHandler("pathBtn")
public void onPathBtnClicked(ClickEvent event) {
  Geometry geometry = new Geometry(Geometry.POLYGON, 0, 0);
  Geometry shell = new Geometry(Geometry.LINEAR_RING, 0, 0);
  shell.setCoordinates(new Coordinate[] { new Coordinate(120, 160), new Coordinate(220, 160),
      new Coordinate(220, 260), new Coordinate(120, 260), new Coordinate(120, 160) });
  Geometry hole = new Geometry(Geometry.LINEAR_RING, 0, 0);
  hole.setCoordinates(new Coordinate[] { new Coordinate(140, 180), new Coordinate(190, 180),
      new Coordinate(190, 230), new Coordinate(140, 230), new Coordinate(140, 180) });
  geometry.setGeometries(new Geometry[] { shell, hole });
  Shape shape = (Shape) GeomajasImpl.getInstance().getGfxUtil().toShape(geometry);
  shape.setFillColor("#0066AA");
  shape.setFillOpacity(0.4);
  shape.setStrokeColor("#004499");
  container.add(shape);
}

代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-javascript-api

/**
 * Create geometry.
 * 
 * @param geometryType
 *            geometry type
 * @param srid
 *            srid
 * @param precision
 *            precision
 */
@ExportConstructor
public static org.geomajas.geometry.Geometry constructor(String geometryType, int srid, int precision) {
  return new org.geomajas.geometry.Geometry(geometryType, srid, precision);
}

代码示例来源:origin: org.geomajas.project/geomajas-project-geometry-jts

throw new  JtsConversionException("Cannot convert null argument");
int srid = geometry.getSrid();
int precision = geometry.getPrecision();
PrecisionModel model;
if (precision == -1) {
com.vividsolutions.jts.geom.Geometry jts;
String geometryType = geometry.getGeometryType();
if (GeometryService.isEmpty(geometry)) {
  jts = createEmpty(factory, geometryType);
  jts = factory.createLineString(convertCoordinates(geometry));
} else if (Geometry.POLYGON.equals(geometryType)) {
  Geometry[] geometries = geometry.getGeometries();
  if (null != geometries && geometries.length > 0) {
    LinearRing exteriorRing = (LinearRing) toJts(geometries[0]);
  Point[] points = new Point[geometry.getGeometries().length];
  jts = factory.createMultiPoint((Point[]) convertGeometries(geometry, points));
} else if (Geometry.MULTI_LINE_STRING.equals(geometryType)) {
  LineString[] lineStrings = new LineString[geometry.getGeometries().length];
  jts = factory.createMultiLineString((LineString[]) convertGeometries(geometry, lineStrings));
} else if (Geometry.MULTI_POLYGON.equals(geometryType)) {
  Polygon[] polygons = new Polygon[geometry.getGeometries().length];
  jts = factory.createMultiPolygon((Polygon[]) convertGeometries(geometry, polygons));
} else {

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-impl

@Override
public void paint(Canvas canvas, Matrix matrix) {
  if (Geometry.POLYGON.equals(geometry.getGeometryType())) {
    canvas.getContext2d().save();
    canvas.getContext2d().setFillStyle(fillStyle);
    canvas.getContext2d().setStrokeStyle(strokeStyle);
    canvas.getContext2d().setLineWidth(strokeWidthPixels / matrix.getXx());
    canvas.getContext2d().beginPath();
    for (Geometry ring : geometry.getGeometries()) {
      Coordinate[] coords = ring.getCoordinates();
      canvas.getContext2d().moveTo(coords[0].getX(), coords[0].getY());
      for (int i = 1; i < coords.length - 1; i++) {
        canvas.getContext2d().lineTo(coords[i].getX(), coords[i].getY());
      }
    }
    canvas.getContext2d().closePath();
    canvas.getContext2d().fill();
    canvas.getContext2d().stroke();
    canvas.getContext2d().restore();
  }
}

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-impl

private void setMultiPolygon(Geometry multiPolygon) {
  if (multiPolygon.getGeometries() != null && multiPolygon.getGeometries().length > 0) {
    setPolygon(multiPolygon.getGeometries()[0]);
    for (int i = 1; i < multiPolygon.getGeometries().length; i++) {
      Geometry polygon = multiPolygon.getGeometries()[i];
      for (int j = 0; j < polygon.getGeometries().length; j++) {
        Geometry ring = polygon.getGeometries()[j];
        Coordinate[] pathCoords = removeLastCoordinate(ring);
        addSubPath(pathCoords, true);
      }
    }
  }
}

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-impl

private static void parseCollection(GeometryType type, Geometry geometry, JSONArray array) {
  Geometry[] geometries = new Geometry[array.size()];
  geometry.setGeometries(geometries);
  for (int i = 0; i < array.size(); i++) {
    switch (type) {
      case POINT:
        geometries[i] = new Geometry(Geometry.POINT, 0, 5);
        parseSimple(GeometryType.POINT, geometries[i], array.get(i).isArray());
        break;
      case LINEARRING:
        geometries[i] = new Geometry(Geometry.LINEAR_RING, 0, 5);
        parseSimple(GeometryType.LINEARRING, geometries[i], array.get(i).isArray());
        break;
      case LINESTRING:
        geometries[i] = new Geometry(Geometry.LINE_STRING, 0, 5);
        parseSimple(GeometryType.LINESTRING, geometries[i], array.get(i).isArray());
        break;
      case POLYGON:
        geometries[i] = new Geometry(Geometry.POLYGON, 0, 5);
        parseCollection(GeometryType.LINEARRING, geometries[i], array.get(i).isArray());
        break;
      default:
        break;
    }
  }
}

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-impl

private Coordinate[] removeLastCoordinate(Geometry ring) {
  if (ring.getCoordinates() == null) {
    return new Coordinate[0];
  }
  Coordinate[] coordinates = ring.getCoordinates();
  Coordinate[] pathCoords = new Coordinate[coordinates.length - 1];
  System.arraycopy(coordinates, 0, pathCoords, 0, coordinates.length - 1);
  return pathCoords;
}

代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-editing-puregwt

if (!indicesToUpdate.containsKey(index)) {
  indicesToUpdate.put(index, false);
  if (!Geometry.POINT.equals(editService.getGeometry().getGeometryType())
      && !Geometry.MULTI_POINT.equals(editService.getGeometry().getGeometryType())) {
    try {
      List<GeometryIndex> neighbors = null;
if (event.getGeometry().getGeometryType().equals(Geometry.POLYGON)) {
  update(null, false);
} else if (event.getGeometry().getGeometryType().equals(Geometry.MULTI_POLYGON)
    && event.getGeometry().getGeometries() != null) {
  for (int i = 0; i < event.getGeometry().getGeometries().length; i++) {
    GeometryIndex index = editService.getIndexService().create(GeometryIndexType.TYPE_GEOMETRY, i);
    indicesToUpdate.put(index, false);

代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-editing-puregwt

private void draw() throws GeometryIndexNotFoundException {
  if (Geometry.POINT.equals(editService.getGeometry().getGeometryType())) {
    drawPoint(null);
  } else if (Geometry.LINE_STRING.equals(editService.getGeometry().getGeometryType())
      || Geometry.LINEAR_RING.equals(editService.getGeometry().getGeometryType())) {
    drawLineString(null);
  } else if (Geometry.POLYGON.equals(editService.getGeometry().getGeometryType())) {
    drawPolygon(null);
  }
}

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-impl

private static void parseSimple(GeometryType type, Geometry geometry, JSONArray array) {
  Coordinate[] coords;
  switch (type) {
    case POINT:
      coords = new Coordinate[1];
      coords[0] = new Coordinate();
      coords[0].setX(array.get(0).isNumber().doubleValue());
      coords[0].setY(array.get(1).isNumber().doubleValue());
      geometry.setCoordinates(coords);
      break;
    case LINEARRING:
    case LINESTRING:
      coords = new Coordinate[array.size()];
      for (int i = 0; i < coords.length; i++) {
        coords[i] = new Coordinate();
        coords[i].setX(array.get(i).isArray().get(0).isNumber().doubleValue());
        coords[i].setY(array.get(i).isArray().get(1).isNumber().doubleValue());
      }
      geometry.setCoordinates(coords);
      break;
    default:
      break;
  }
}

代码示例来源:origin: org.geomajas.project/geomajas-project-geometry-jts

Geometry dto = new Geometry(geometryType, srid, precision);
if (geometry.isEmpty()) {
  dto.setCoordinates(convertCoordinates(geometry));
} else if (geometry instanceof LinearRing) {
  dto.setCoordinates(convertCoordinates(geometry));
} else if (geometry instanceof LineString) {
  dto.setCoordinates(convertCoordinates(geometry));
} else if (geometry instanceof Polygon) {
  Polygon polygon = (Polygon) geometry;
  dto.setGeometries(geometries);
} else if (geometry instanceof MultiPoint) {
  dto.setGeometries(convertGeometries(geometry));
} else if (geometry instanceof MultiLineString) {
  dto.setGeometries(convertGeometries(geometry));
} else if (geometry instanceof MultiPolygon) {
  dto.setGeometries(convertGeometries(geometry));
} else {
  throw new JtsConversionException("Cannot convert geometry: Unsupported type.");

代码示例来源:origin: org.geomajas/geomajas-gwt-client-impl

/**
 * Search for features at a certain location.
 * 
 * @param location
 *            The location to check.
 * @param isShift
 *            Is the shift button pressed down?
 */
private void searchAtLocation(Coordinate location, boolean isShift) {
  Geometry point = new Geometry(Geometry.POINT, 0, -1);
  point.setCoordinates(new Coordinate[] { location });
  mapPresenter.getFeatureService().search(point, pixelsToUnits(pixelTolerance), QueryType.INTERSECTS,
      searchLayerType, -1, new SelectionCallback(isShift, false));
}

代码示例来源:origin: org.geomajas.plugin/geomajas-client-gwt2-plugin-editing-example-jar

@UiHandler("createBtn")
protected void onCreateButtonClicked(ClickEvent event) {
  // Create an empty point geometry. It has no coordinates yet. That is up to the user...
  Geometry line = new Geometry(Geometry.LINE_STRING, 0, -1);
  editService.start(line);
  // Set the editing service in "INSERTING" mode. Make sure it starts inserting in the correct index.
  GeometryIndex index = editService.getIndexService().create(GeometryIndexType.TYPE_VERTEX, 0);
  editService.setEditingState(GeometryEditState.INSERTING);
  editService.setInsertIndex(index);
  // Et voila, the user may now click on the map...
}

代码示例来源:origin: org.geomajas/geomajas-gwt-client-impl

@Override
public void paint(Canvas canvas, Matrix matrix) {
  if (Geometry.POLYGON.equals(geometry.getGeometryType())) {
    canvas.getContext2d().save();
    canvas.getContext2d().setFillStyle(fillStyle);
    canvas.getContext2d().setStrokeStyle(strokeStyle);
    canvas.getContext2d().setLineWidth(strokeWidthPixels / matrix.getXx());
    canvas.getContext2d().beginPath();
    for (Geometry ring : geometry.getGeometries()) {
      Coordinate[] coords = ring.getCoordinates();
      canvas.getContext2d().moveTo(coords[0].getX(), coords[0].getY());
      for (int i = 1; i < coords.length - 1; i++) {
        canvas.getContext2d().lineTo(coords[i].getX(), coords[i].getY());
      }
    }
    canvas.getContext2d().closePath();
    canvas.getContext2d().fill();
    canvas.getContext2d().stroke();
    canvas.getContext2d().restore();
  }
}

代码示例来源:origin: org.geomajas/geomajas-gwt-client-impl

private void setMultiPolygon(Geometry multiPolygon) {
  if (multiPolygon.getGeometries() != null && multiPolygon.getGeometries().length > 0) {
    setPolygon(multiPolygon.getGeometries()[0]);
    for (int i = 1; i < multiPolygon.getGeometries().length; i++) {
      Geometry polygon = multiPolygon.getGeometries()[i];
      for (int j = 0; j < polygon.getGeometries().length; j++) {
        Geometry ring = polygon.getGeometries()[j];
        Coordinate[] pathCoords = removeLastCoordinate(ring);
        addSubPath(pathCoords, true);
      }
    }
  }
}

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-impl

private void setMultiLineString(Geometry multiLineString) {
  if (multiLineString.getGeometries() != null && multiLineString.getGeometries().length > 0) {
    setLineString(multiLineString.getGeometries()[0]);
    for (int i = 1; i < multiLineString.getGeometries().length; i++) {
      Geometry lineString = multiLineString.getGeometries()[i];
      addSubPath(clone(lineString.getCoordinates()), false);
    }
  }
}

代码示例来源:origin: org.geomajas/geomajas-client-gwt2-example-jar

@UiHandler("geometryBtn")
public void onGeometryBtnClicked(ClickEvent event) {
  try {
    Geometry polygon = WktService
        .toGeometry("POLYGON ((0 0, 0 0.7, 0.7 0.7, 0 0),(0.1 0.2, 0.1 0.4, 0.3 0.4, 0.1 0.2))");
    Geometry line = WktService.toGeometry("LINESTRING (-2 0, -2 0.7, -1.3 0, -1.3 0.7)");
    Geometry point = WktService.toGeometry("POINT (-3.5 0.5)");
    Geometry multiPolygon = new Geometry(Geometry.MULTI_POLYGON, 0, 5);
    Matrix m1 = new Matrix(1, 0, 0, 1, -0.5, -2);
    Matrix m2 = new Matrix(1, 0, 0, 1, 0.5, -2);
    Matrix m3 = new Matrix(1, 0, 0, 1, 0, -1);
    multiPolygon.setGeometries(new Geometry[] { transform(polygon, m1), transform(polygon, m2),
        transform(polygon, m3), });
    Geometry multiLinestring = new Geometry(Geometry.MULTI_LINE_STRING, 0, 5);
    multiLinestring.setGeometries(new Geometry[] { transform(line, m1), transform(line, m2),
        transform(line, m3), });
    Geometry mp = new Geometry(Geometry.MULTI_POINT, 0, 5);
    mp.setGeometries(new Geometry[] { transform(point, m1), transform(point, m2), transform(point, m3), });
    container.add(scaleAndStyle(polygon));
    container.add(scaleAndStyle(line));
    container.add(scaleAndStyle(point));
    container.add(scaleAndStyle(multiPolygon));
    container.add(scaleAndStyle(multiLinestring));
    container.add(scaleAndStyle(mp));
  } catch (WktException e) {
    // not possible
  }
}

相关文章