Clips a geometry to a tile.

@param way                 the way
@param geometry            the geometry
@param tileCoordinate      the tile coordinate
@param enlargementInMeters the bounding box buffer
@return the clipped geometry
515102
public static Geometry clipToTile(TDWay way, Geometry geometry, TileCoordinate tileCoordinate,
                                      int enlargementInMeters) {
        Geometry tileBBJTS = null;
        Geometry ret = null;

        // create tile bounding box
        tileBBJTS = tileToJTSGeometry(tileCoordinate.getX(), tileCoordinate.getY(), tileCoordinate.getZoomlevel(),
                enlargementInMeters);

        // clip the geometry by intersection with the bounding box of the tile
        // may throw a TopologyException
        try {
            if (!geometry.isValid()) {
                // this should stop the problem of non-noded intersections that trigger an error when
                // clipping
                LOGGER.warning("invalid geometry prior to tile clipping, trying to repair " + way.getId());
                geometry = JTSUtils.repairInvalidPolygon(geometry);
                if (!geometry.isValid()) {
                    LOGGER.warning("invalid geometry even after attempt to fix " + way.getId());
                }
            }
            ret = tileBBJTS.intersection(geometry);
            // according to Ludwig (see issue332) valid polygons may become invalid by clipping (at least
            // in the Python shapely library
            // we need to investigate this more closely and write approriate test cases
            // for now, I check whether the resulting polygon is valid and if not try to repair it
            if ((ret instanceof Polygon || ret instanceof MultiPolygon) && !ret.isValid()) {
                LOGGER.warning("clipped way is not valid, trying to repair it: " + way.getId());
                ret = JTSUtils.repairInvalidPolygon(ret);
                if (ret == null) {
                    way.setInvalid(true);
                    LOGGER.warning("could not repair invalid polygon: " + way.getId());
                }
            }
        } catch (TopologyException e) {
            LOGGER.log(Level.WARNING, "JTS cannot clip way, not storing it in data file: " + way.getId(), e);
            way.setInvalid(true);
            return null;
        }
        return ret;
    }
495272
function overzoomGeometry(rings, nativeTile, newExtent, newTile) {
  var diffZ = newTile.level - nativeTile.level;
  if (diffZ === 0) {
    return rings;
  } else {
    var newRings = [];
    // (offsetX, offsetY) is the (0,0) of the new tile
    var offsetX = newExtent * (newTile.x - (nativeTile.x << diffZ));
    var offsetY = newExtent * (newTile.y - (nativeTile.y << diffZ));
    for (var i = 0; i < rings.length; i++) {
      var ring = [];
      for (var i2 = 0; i2 < rings[i].length; i2++) {
        ring.push(rings[i][i2].sub(new Point(offsetX, offsetY)));
      }
      newRings.push(ring);
    }
    return newRings;
  }
}
1118772
public JsHandlerRegistration addGeometryEditRemoveHandler(final GeometryEditRemoveHandler handler) {
		org.geomajas.plugin.editing.client.event.GeometryEditRemoveHandler h;
		h = new org.geomajas.plugin.editing.client.event.GeometryEditRemoveHandler() {

			public void onGeometryEditRemove(GeometryEditRemoveEvent event) {
				List<GeometryIndex> indices = event.getIndices();
				handler.onGeometryEditRemove(new org.geomajas.plugin.editing.jsapi.client.event.GeometryEditRemoveEvent(
						event.getGeometry(), indices.toArray(new GeometryIndex[indices.size()])));
			}
		};
		HandlerRegistration registration = delegate.addGeometryEditRemoveHandler(h);
		return new JsHandlerRegistration(new HandlerRegistration[] { registration });
	}
102252
public Coordinate getCoordinate(Geometry geometry) {
		LineString lineString = getLineString(geometry);
		if (lineString != null && coordinateIndex >= 0) {
			return lineString.getCoordinateN(coordinateIndex);
		}
		return null;
	}
751795
public static TileGrid tileGridZoomIncrease(TileGrid tileGrid,
			int zoomLevels) {
		long minX = tileGridMinZoomIncrease(tileGrid.getMinX(), zoomLevels);
		long maxX = tileGridMaxZoomIncrease(tileGrid.getMaxX(), zoomLevels);
		long minY = tileGridMinZoomIncrease(tileGrid.getMinY(), zoomLevels);
		long maxY = tileGridMaxZoomIncrease(tileGrid.getMaxY(), zoomLevels);
		TileGrid newTileGrid = new TileGrid(minX, minY, maxX, maxY);
		return newTileGrid;
	}
1257269
public static Polygon makeEnvelope(double xmin, double ymin, double xmax, double ymax, int srid) {
        Polygon geom = makeEnvelope(xmin, ymin, xmax, ymax);
        geom.setSRID(srid);
        return geom;
    }
629248
public static boolean isGeoPackageExtension(GeometryType geometryType) {
		return GeometryCodes.getCode(geometryType) >= GeometryCodes
				.getCode(GeometryType.CIRCULARSTRING)
				&& GeometryCodes.getCode(geometryType) <= GeometryCodes
						.getCode(GeometryType.SURFACE);
	}
1146187
private static void getArealGeometry(ArrayList<Polygon> polygones, Geometry geometry) {
         for (int i = 0; i < geometry.getNumGeometries(); i++) {
            Geometry subGeom = geometry.getGeometryN(i);
            if(subGeom instanceof Polygon){
                polygones.add((Polygon) subGeom);
            }
            else if (subGeom instanceof GeometryCollection){
                getArealGeometry(polygones, subGeom);
            }
        }
    }
1190960
private static TileConfiguration createTileConfiguration(MapConfiguration mapConfig,
			ClientVectorLayerInfo layerInfo, final ViewPort viewPort) {
		TileConfiguration tileConfig = new TileConfiguration();
		ClientMapInfo mapInfo = mapConfig.getHintValue(GeomajasServerExtension.MAPINFO);
		tileConfig.setTileWidth(mapInfo.getPreferredPixelsPerTile().getWidth());
		tileConfig.setTileHeight(mapInfo.getPreferredPixelsPerTile().getHeight());
		List<Double> resolutions = new ArrayList<Double>();
		for (int i = 0; i < viewPort.getResolutionCount(); i++) {
			resolutions.add(viewPort.getResolution(i));
		}
		tileConfig.setResolutions(resolutions);
		if (layerInfo.getMaxExtent() != null) {
			tileConfig.setTileOrigin(BboxService.getOrigin(layerInfo.getMaxExtent()));
		} else {
			tileConfig.setTileOrigin(new Coordinate());
		}
		return tileConfig;
	}
947796
function(prepend, tileSize) {
        var grid = this.grid;
        var colIndex = prepend ? 0 : (grid[0].length - 1);
        var sign = prepend ? -1 : 1;
        var tileLayout = this.gridLayout;
        tileLayout.startcol += sign;

        for (var i=0, len=grid.length; i<len; i++) {
            var row = grid[i];
            var position = row[colIndex].position.clone();
            var tile = row[prepend ? 'pop' : 'shift']();            
            position.x += tileSize.w * sign;
            tile.moveTo(this.getTileBoundsForGridIndex(i, colIndex), position);
            row[prepend ? 'unshift' : 'push'](tile);
        }
    }
246652
def tiles_from_geom(self, geometry, zoom):
        
        validate_zoom(zoom)
        if geometry.is_empty:
            return
        if not geometry.is_valid:
            raise ValueError("no valid geometry: %s" % geometry.type)
        if geometry.geom_type == "Point":
            yield self.tile_from_xy(geometry.x, geometry.y, zoom)
        elif geometry.geom_type == "MultiPoint":
            for point in geometry:
                yield self.tile_from_xy(point.x, point.y, zoom)
        elif geometry.geom_type in (
            "LineString", "MultiLineString", "Polygon", "MultiPolygon",
            "GeometryCollection"
        ):
            prepared_geometry = prep(clip_geometry_to_srs_bounds(geometry, self))
            for tile in self.tiles_from_bbox(geometry, zoom):
                if prepared_geometry.intersects(tile.bbox()):
                    yield tile
489432
public Envelope TileLatLonBounds( int tx, int ty, int zoom ) {
        double[] wsenBounds = TileBounds(tx, ty, zoom);
        double[] sw = MetersToLatLon(wsenBounds[0], wsenBounds[1]);
        double[] ne = MetersToLatLon(wsenBounds[2], wsenBounds[3]);
        return new Envelope(sw[1], ne[1], sw[0], ne[0]);
    }
729903
public void clip() {
        int x = (int) (projection.canvas.getWidth() * projection.canvas.margin);
        int y = (int) (projection.canvas.getHeight() * projection.canvas.margin);
        int w = (int) (projection.canvas.getWidth() * (1 - 2 * projection.canvas.margin));
        int h = (int) (projection.canvas.getHeight() * (1 - 2 * projection.canvas.margin));
        originalClip = g2d.getClip();
        g2d.clipRect(x, y, w, h);
    }
1214483
function (bounds) {
        bounds = this.adjustBounds(bounds);
        var mapRes = this.map.getResolution();
        var scale = Math.round((this.map.getScale() * 10000)) / 10000;
        var pX = Math.round(bounds.left / mapRes);
        var pY = -Math.round(bounds.top / mapRes);

        var metaX = Math.floor(pX / this.tileSize.w / this.params.metaTileSize.w) * this.tileSize.w * this.params.metaTileSize.w;
        var metaY = Math.floor(pY / this.tileSize.h / this.params.metaTileSize.h) * this.tileSize.h * this.params.metaTileSize.h;
    
        var components = [
            "/",
            this.params.map,
            "/",
            scale,
            "/",
            this.params.g.replace(/\s/g, '_'),
            "/def/t", 
            metaY,
            "/l",
            metaX,
            "/t",
            pY,
            "l",
            pX,
            ".",
            this.extension
          ];

        var url = this.url;

        if (OpenLayers.Util.isArray(url)) {
            url = this.selectUrl(components.join(''), url);
        }
        return url + components.join("");
    }
252927
public static TileGrid tileGridZoom(TileGrid tileGrid, int fromZoom,
			int toZoom) {

		TileGrid newTileGrid = null;

		int zoomChange = toZoom - fromZoom;
		if (zoomChange > 0) {
			newTileGrid = tileGridZoomIncrease(tileGrid, zoomChange);
		} else if (zoomChange < 0) {
			zoomChange = Math.abs(zoomChange);
			newTileGrid = tileGridZoomDecrease(tileGrid, zoomChange);
		} else {
			newTileGrid = tileGrid;
		}

		return newTileGrid;
	}
481012
public static List<Polygon> createSimpleDirectionArrow( Geometry... geometries ) {
        List<Polygon> polygons = new ArrayList<>();
        for( Geometry geometry : geometries ) {
            for( int i = 0; i < geometry.getNumGeometries(); i++ ) {
                Geometry geometryN = geometry.getGeometryN(i);
                if (geometryN instanceof LineString) {
                    LineString line = (LineString) geometryN;
                    polygons.addAll(makeArrows(line));
                } else if (geometryN instanceof Polygon) {
                    Polygon polygonGeom = (Polygon) geometryN;
                    LineString exteriorRing = polygonGeom.getExteriorRing();
                    polygons.addAll(makeArrows(exteriorRing));
                    int numInteriorRing = polygonGeom.getNumInteriorRing();
                    for( int j = 0; j < numInteriorRing; j++ ) {
                        LineString interiorRingN = polygonGeom.getInteriorRingN(j);
                        polygons.addAll(makeArrows(interiorRingN));
                    }
                }
            }
        }
        return polygons;
    }
1228783
public BufferedImage drawTileQueryAll(int x, int y, int zoom) {

		BoundingBox boundingBox = TileBoundingBoxUtils
				.getWebMercatorBoundingBox(x, y, zoom);

		BufferedImage image = null;

		// Query for all features
		FeatureResultSet resultSet = featureDao.queryForAll();

		try {

			int totalCount = resultSet.getCount();

			// Draw if at least one geometry exists
			if (totalCount > 0) {

				if (maxFeaturesPerTile == null
						|| totalCount <= maxFeaturesPerTile) {

					// Draw the tile image
					image = drawTile(zoom, boundingBox, resultSet);

				} else if (maxFeaturesTileDraw != null) {

					// Draw the unindexed max features tile
					image = maxFeaturesTileDraw.drawUnindexedTile(tileWidth,
							tileHeight, totalCount, resultSet);
				}

			}
		} finally {
			resultSet.close();
		}

		return image;
	}