Build the OSM URL based on a given envelope

@param geometryEnvelope
@return
192613
private static URL createOsmUrl(Envelope geometryEnvelope) {
        try {
            return new URL(OSM_API_URL + "map?bbox=" + geometryEnvelope.getMinX() + ","
                    + geometryEnvelope.getMinY()
                    + "," + geometryEnvelope.getMaxX() + "," + geometryEnvelope.getMaxY());
        } catch (MalformedURLException e) {
            throw new IllegalStateException(e);
        }
    }
1306375
public static String envelope2WKT(org.locationtech.jts.geom.Envelope env) {
        GeometryFactory gf = GeometryUtilities.gf();
        Geometry geometry = gf.toGeometry(env);
        return geometry.toText();
    }
495883
public static void downloadOSMFile(File file, Envelope geometryEnvelope) throws IOException {
        HttpURLConnection urlCon = (HttpURLConnection) createOsmUrl(geometryEnvelope).openConnection();
        urlCon.setRequestMethod("GET");
        urlCon.connect();
        switch (urlCon.getResponseCode()) {
            case 400:
                throw new IOException("Error : Cannot query the OSM API with the following bounding box");
            case 509:
                throw new IOException("Error: You have downloaded too much data. Please try again later");
            default:
                InputStream in = urlCon.getInputStream();
                OutputStream out = new FileOutputStream(file);
                try {
                    byte[] data = new byte[4096];
                    while (true) {
                        int numBytes = in.read(data);
                        if (numBytes == -1) {
                            break;
                        }
                        out.write(data, 0, numBytes);
                    }
                } finally {
                    out.close();
                    in.close();
                }       break;
        }
    }
853560
private static String buildUrl(TileCode tileCode, TileMap tileMap, String baseTmsUrl) {
		if (tileCode == null || tileMap == null || baseTmsUrl == null) {
			throw new IllegalArgumentException("All parameters are required");
		}
		
		StringBuilder builder;

		// assuming they are ordered:
		TileSet tileSet = tileMap.getTileSets().getTileSets().get(tileCode.getTileLevel());
		String href = tileSet.getHref();
		if (href.startsWith("http://") || href.startsWith("https://")) {
			builder = new StringBuilder(href);
			if (!href.endsWith("/")) {
				builder.append("/");
			}
		} else {
			builder = new StringBuilder(baseTmsUrl);
			if (!baseTmsUrl.endsWith("/")) {
				builder.append("/");
			}
			builder.append(href);
			builder.append("/");
		}

		builder.append(tileCode.getX());
		builder.append("/");
		builder.append(tileCode.getY());
		builder.append(".");
		builder.append(tileMap.getTileFormat().getExtension());
		return builder.toString();
	}
300985
public Geometry toGeometry(GoogleMapShape shape) {

        Geometry geometry = null;
        Object shapeObject = shape.getShape();

        switch (shape.getGeometryType()) {

            case POINT:
                LatLng point = null;
                switch (shape.getShapeType()) {
                    case LAT_LNG:
                        point = (LatLng) shapeObject;
                        break;
                    case MARKER_OPTIONS:
                        MarkerOptions markerOptions = (MarkerOptions) shapeObject;
                        point = markerOptions.getPosition();
                        break;
                    case MARKER:
                        Marker marker = (Marker) shapeObject;
                        point = marker.getPosition();
                        break;
                    default:
                        throw new GeoPackageException("Not a valid "
                                + shape.getGeometryType().getName() + " shape type: "
                                + shape.getShapeType());
                }
                if (point != null) {
                    geometry = toPoint(point);
                }

                break;
            case LINESTRING:
            case CIRCULARSTRING:
                List<LatLng> lineStringPoints = null;
                switch (shape.getShapeType()) {
                    case POLYLINE_OPTIONS:
                        PolylineOptions polylineOptions = (PolylineOptions) shapeObject;
                        lineStringPoints = polylineOptions.getPoints();
                        break;
                    case POLYLINE:
                        Polyline polyline = (Polyline) shapeObject;
                        lineStringPoints = polyline.getPoints();
                        break;
                    case POLYLINE_MARKERS:
                        PolylineMarkers polylineMarkers = (PolylineMarkers) shapeObject;
                        if (!polylineMarkers.isValid()) {
                            throw new GeoPackageException(
                                    PolylineMarkers.class.getSimpleName()
                                            + " is not valid to create "
                                            + shape.getGeometryType().getName());
                        }
                        if (!polylineMarkers.isDeleted()) {
                            lineStringPoints = getPointsFromMarkers(polylineMarkers
                                    .getMarkers());
                        }
                        break;
                    default:
                        throw new GeoPackageException("Not a valid "
                                + shape.getGeometryType().getName() + " shape type: "
                                + shape.getShapeType());
                }
                if (lineStringPoints != null) {
                    switch (shape.getGeometryType()) {
                        case LINESTRING:
                            geometry = toLineString(lineStringPoints);
                            break;
                        case CIRCULARSTRING:
                            geometry = toCircularString(lineStringPoints);
                            break;
                        default:
                            throw new GeoPackageException("Unhandled "
                                    + shape.getGeometryType().getName());
                    }
                }

                break;
            case POLYGON:
                List<LatLng> polygonPoints = null;
                List<List<LatLng>> holePointList = null;
                switch (shape.getShapeType()) {
                    case POLYGON_OPTIONS:
                        PolygonOptions polygonOptions = (PolygonOptions) shapeObject;
                        polygonPoints = polygonOptions.getPoints();
                        holePointList = polygonOptions.getHoles();
                        break;
                    case POLYGON:
                        com.google.android.gms.maps.model.Polygon polygon = (com.google.android.gms.maps.model.Polygon) shapeObject;
                        polygonPoints = polygon.getPoints();
                        holePointList = polygon.getHoles();
                        break;
                    case POLYGON_MARKERS:
                        PolygonMarkers polygonMarkers = (PolygonMarkers) shapeObject;
                        if (!polygonMarkers.isValid()) {
                            throw new GeoPackageException(
                                    PolygonMarkers.class.getSimpleName()
                                            + " is not valid to create "
                                            + shape.getGeometryType().getName());
                        }
                        if (!polygonMarkers.isDeleted()) {
                            polygonPoints = getPointsFromMarkers(polygonMarkers
                                    .getMarkers());
                            holePointList = new ArrayList<List<LatLng>>();
                            for (PolygonHoleMarkers hole : polygonMarkers.getHoles()) {
                                if (!hole.isDeleted()) {
                                    List<LatLng> holePoints = getPointsFromMarkers(hole
                                            .getMarkers());
                                    holePointList.add(holePoints);
                                }
                            }
                        }
                        break;
                    default:
                        throw new GeoPackageException("Not a valid "
                                + shape.getGeometryType().getName() + " shape type: "
                                + shape.getShapeType());
                }
                if (polygonPoints != null) {
                    geometry = toPolygon(polygonPoints, holePointList);
                }

                break;
            case MULTIPOINT:
                List<LatLng> multiPoints = null;
                switch (shape.getShapeType()) {
                    case MULTI_LAT_LNG:
                        MultiLatLng multiLatLng = (MultiLatLng) shapeObject;
                        multiPoints = multiLatLng.getLatLngs();
                        break;
                    case MULTI_MARKER:
                        MultiMarker multiMarker = (MultiMarker) shapeObject;
                        multiPoints = getPointsFromMarkers(multiMarker.getMarkers());
                        break;
                    default:
                        throw new GeoPackageException("Not a valid "
                                + shape.getGeometryType().getName() + " shape type: "
                                + shape.getShapeType());
                }
                if (multiPoints != null) {
                    geometry = toMultiPoint(multiPoints);
                }

                break;
            case MULTILINESTRING:
            case COMPOUNDCURVE:
                switch (shape.getShapeType()) {
                    case MULTI_POLYLINE_OPTIONS:
                        MultiPolylineOptions multiPolylineOptions = (MultiPolylineOptions) shapeObject;
                        switch (shape.getGeometryType()) {
                            case MULTILINESTRING:
                                geometry = toMultiLineStringFromOptions(multiPolylineOptions);
                                break;
                            case COMPOUNDCURVE:
                                geometry = toCompoundCurveFromOptions(multiPolylineOptions);
                                break;
                            default:
                                throw new GeoPackageException("Unhandled "
                                        + shape.getGeometryType().getName());
                        }
                        break;
                    case MULTI_POLYLINE:
                        MultiPolyline multiPolyline = (MultiPolyline) shapeObject;
                        switch (shape.getGeometryType()) {
                            case MULTILINESTRING:
                                geometry = toMultiLineString(multiPolyline.getPolylines());
                                break;
                            case COMPOUNDCURVE:
                                geometry = toCompoundCurve(multiPolyline.getPolylines());
                                break;
                            default:
                                throw new GeoPackageException("Unhandled "
                                        + shape.getGeometryType().getName());
                        }
                        break;
                    case MULTI_POLYLINE_MARKERS:
                        MultiPolylineMarkers multiPolylineMarkers = (MultiPolylineMarkers) shapeObject;
                        if (!multiPolylineMarkers.isValid()) {
                            throw new GeoPackageException(
                                    MultiPolylineMarkers.class.getSimpleName()
                                            + " is not valid to create "
                                            + shape.getGeometryType().getName());
                        }
                        if (!multiPolylineMarkers.isDeleted()) {
                            List<List<LatLng>> multiPolylineMarkersList = new ArrayList<List<LatLng>>();
                            for (PolylineMarkers polylineMarkers : multiPolylineMarkers
                                    .getPolylineMarkers()) {
                                if (!polylineMarkers.isDeleted()) {
                                    multiPolylineMarkersList
                                            .add(getPointsFromMarkers(polylineMarkers
                                                    .getMarkers()));
                                }
                            }
                            switch (shape.getGeometryType()) {
                                case MULTILINESTRING:
                                    geometry = toMultiLineStringFromList(multiPolylineMarkersList);
                                    break;
                                case COMPOUNDCURVE:
                                    geometry = toCompoundCurveFromList(multiPolylineMarkersList);
                                    break;
                                default:
                                    throw new GeoPackageException("Unhandled "
                                            + shape.getGeometryType().getName());
                            }
                        }
                        break;
                    default:
                        throw new GeoPackageException("Not a valid "
                                + shape.getGeometryType().getName() + " shape type: "
                                + shape.getShapeType());
                }

                break;
            case MULTIPOLYGON:
                switch (shape.getShapeType()) {
                    case MULTI_POLYGON_OPTIONS:
                        MultiPolygonOptions multiPolygonOptions = (MultiPolygonOptions) shapeObject;
                        geometry = toMultiPolygonFromOptions(multiPolygonOptions);
                        break;
                    case MULTI_POLYGON:
                        mil.nga.geopackage.map.geom.MultiPolygon multiPolygon = (mil.nga.geopackage.map.geom.MultiPolygon) shapeObject;
                        geometry = toMultiPolygon(multiPolygon.getPolygons());
                        break;
                    case MULTI_POLYGON_MARKERS:
                        MultiPolygonMarkers multiPolygonMarkers = (MultiPolygonMarkers) shapeObject;
                        if (!multiPolygonMarkers.isValid()) {
                            throw new GeoPackageException(
                                    MultiPolygonMarkers.class.getSimpleName()
                                            + " is not valid to create "
                                            + shape.getGeometryType().getName());
                        }
                        if (!multiPolygonMarkers.isDeleted()) {
                            List<Polygon> multiPolygonMarkersList = new ArrayList<Polygon>();
                            for (PolygonMarkers polygonMarkers : multiPolygonMarkers
                                    .getPolygonMarkers()) {

                                if (!polygonMarkers.isDeleted()) {

                                    List<LatLng> multiPolygonPoints = getPointsFromMarkers(polygonMarkers
                                            .getMarkers());
                                    List<List<LatLng>> multiPolygonHolePoints = new ArrayList<List<LatLng>>();
                                    for (PolygonHoleMarkers hole : polygonMarkers
                                            .getHoles()) {
                                        if (!hole.isDeleted()) {
                                            List<LatLng> holePoints = getPointsFromMarkers(hole
                                                    .getMarkers());
                                            multiPolygonHolePoints.add(holePoints);
                                        }
                                    }

                                    multiPolygonMarkersList
                                            .add(toPolygon(multiPolygonPoints,
                                                    multiPolygonHolePoints));
                                }

                            }
                            geometry = createMultiPolygon(multiPolygonMarkersList);
                        }
                        break;
                    default:
                        throw new GeoPackageException("Not a valid "
                                + shape.getGeometryType().getName() + " shape type: "
                                + shape.getShapeType());
                }
                break;

            case POLYHEDRALSURFACE:
            case TIN:
            case TRIANGLE:
                throw new GeoPackageException("Unsupported GeoPackage type: "
                        + shape.getGeometryType());
            case GEOMETRYCOLLECTION:
                @SuppressWarnings("unchecked")
                List<GoogleMapShape> shapeList = (List<GoogleMapShape>) shapeObject;
                GeometryCollection<Geometry> geometryCollection = new GeometryCollection<Geometry>(
                        false, false);
                for (GoogleMapShape shapeListItem : shapeList) {
                    Geometry subGeometry = toGeometry(shapeListItem);
                    if (subGeometry != null) {
                        geometryCollection.addGeometry(subGeometry);
                    }
                }
                if (geometryCollection.numGeometries() > 0) {
                    geometry = geometryCollection;
                }
                break;
            default:
        }

        return geometry;
    }
306454
public static String getExtensionName(GeometryType geometryType) {

		if (!isExtension(geometryType)) {
			throw new GeoPackageException(GeometryType.class.getSimpleName()
					+ " is not an extension: " + geometryType.getName());
		}

		if (!isGeoPackageExtension(geometryType)) {
			throw new GeoPackageException(
					GeometryType.class.getSimpleName()
							+ " is not a GeoPackage extension, User-Defined requires an author: "
							+ geometryType.getName());
		}

		String extensionName = GeoPackageConstants.GEO_PACKAGE_EXTENSION_AUTHOR
				+ Extensions.EXTENSION_NAME_DIVIDER
				+ GeoPackageConstants.GEOMETRY_EXTENSION_PREFIX
				+ Extensions.EXTENSION_NAME_DIVIDER + geometryType.getName();

		return extensionName;
	}
1205990
function(geometryModel) {
      if(geometryModel.isPoint()) {
        return new cdb.geo.leaflet.PointView(geometryModel);
      }
      return new cdb.geo.leaflet.PathView(geometryModel);
    }
955115
@Override
  public WebViewMapFragment build() {
    if (options == null) {
      options = new MapboxWebMapType(accessToken, mapId);
    }
    if (options instanceof MapboxWebMapType) {
      return MapboxWebViewMapFragment.newInstance(options);
    }
    throw new IllegalStateException("Unable to build MapboxWebMapViewFragment." +
        "  options == '" + options + "'");
  }
664946
public static String buildCanvasUrl(String canvasBaseUrl, int canvasAPIVersion, String canvasMethod, Map<String, List<String>> parameters) {
        canvasMethod = removeForwardSlashIfExists(canvasMethod);
        String url = canvasBaseUrl + "/api/v" +  canvasAPIVersion + "/" + canvasMethod;
        String finalUrl = url + HttpParameterBuilder.buildParameters(parameters);
        LOG.debug("Built Canvas url - " + finalUrl);
        return finalUrl;
    }
1148014
public long count(GeometryEnvelope envelope) {
		long count = 0;
		switch (getIndexedType()) {
		case GEOPACKAGE:
			count = featureTableIndex.count(envelope);
			break;
		case RTREE:
			count = rTreeIndexTableDao.count(envelope);
			break;
		default:
			count = manualFeatureQuery.count(envelope);
		}
		return count;
	}
1327345
public static <T extends Geometry> GeometryExpression<T> asGeometry(Expression<T> expr) {
        Expression<T> underlyingMixin = ExpressionUtils.extract(expr);
        if (underlyingMixin instanceof PathImpl) {
            return new GeometryPath<T>((PathImpl<T>) underlyingMixin);
        } else if (underlyingMixin instanceof OperationImpl) {
            return new GeometryOperation<T>((OperationImpl<T>) underlyingMixin);
        } else {
            return new GeometryExpression<T>(underlyingMixin) {

                private static final long serialVersionUID = -6714044005570420009L;

                @Override
                public <R, C> R accept(Visitor<R, C> v, C context) {
                    return this.mixin.accept(v, context);
                }

            };
        }
    }
801600
public Swagger build(Collection<Route> routes) {

        Swagger swagger = new Swagger();

        // application metadata
        Info info = new Info();
        info.setTitle(settings.getString("swagger.info.title", settings.getApplicationName()));
        info.setVersion(settings.getString("swagger.info.version", settings.getApplicationVersion()));
        info.setDescription(ClassUtil.loadStringResource(settings.getFileUrl("swagger.info.description", "classpath:swagger/info.md")));

        // api support contact
        Contact contact = new Contact();
        contact.setName(settings.getString("swagger.info.contact.name", null));
        contact.setUrl(settings.getString("swagger.info.contact.url", null));
        contact.setEmail(settings.getString("swagger.info.contact.email", null));
        if (Strings.isNullOrEmpty(contact.getName())
                && Strings.isNullOrEmpty(contact.getUrl())
                && Strings.isNullOrEmpty(contact.getEmail())) {
            // no contact info
        } else {
            info.setContact(contact);
        }

        // License
        License license = new License();
        license.setName(settings.getString("swagger.info.license.name", null));
        license.setUrl(settings.getString("swagger.info.license.url", null));
        if (Strings.isNullOrEmpty(license.getName())
                && Strings.isNullOrEmpty(license.getUrl())) {
            // no license
        } else {
            info.setLicense(license);
        }

        swagger.setInfo(info);

        // External docs
        ExternalDocs externalDocs = new ExternalDocs();
        externalDocs.setUrl(settings.getString("swagger.externalDocs.url", null));
        externalDocs.setDescription(settings.getString("swagger.externalDocs.description", null));
        if (Strings.isNullOrEmpty(externalDocs.getUrl())) {
            // no external docs
        } else {
            swagger.setExternalDocs(externalDocs);
        }

        // host (name or ip) serving the API
        String host = Strings.emptyToNull(settings.getString("swagger.host", null));
        if (host != null) {
            swagger.setHost(host);
        }

        // transport and base url details
        List<String> configuredSchemes = settings.getStrings("swagger.schemes");
        List<Scheme> schemes = new ArrayList<>();
        if (configuredSchemes.isEmpty()) {
            Scheme s = Scheme.forValue(settings.getApplicationScheme());
            if (s != null) {
                schemes.add(s);
            }
        } else {
            // set configured schemes
            for (String scheme : configuredSchemes) {
                Scheme s = Scheme.forValue(scheme.trim());
                if (s != null) {
                    schemes.add(s);
                }
            }
        }
        swagger.setSchemes(schemes);

        String contextPath = StringUtils.removeStart(Strings.emptyToNull(settings.getString(Settings.Setting.undertow_contextPath, null)), "/");
        String servletPath = StringUtils.removeStart(Strings.emptyToNull(settings.getString(RestServlet.SETTING_URL, null)), "/");
        String apiPath = StringUtils.removeStart(Strings.emptyToNull(settings.getString("swagger.basePath", null)), "/");
        String applicationApiPath = Joiner.on("/").skipNulls().join(contextPath, servletPath, apiPath);
        swagger.setBasePath(applicationApiPath);

        // register each valid RESTful route
        for (Route route : routes) {
            if (route.getRouteHandler() instanceof ControllerHandler) {
                ControllerHandler handler = (ControllerHandler) route.getRouteHandler();
                if (canRegister(route, handler)) {
                    registerOperation(swagger, route, handler);
                }
            }
        }

        return swagger;
    }
952067
private Envelope getLayerEnvelope(ProxyLayerSupport layer) {
		Bbox bounds = layer.getLayerInfo().getMaxExtent();
		return new Envelope(bounds.getX(), bounds.getMaxX(), bounds.getY(), bounds.getMaxY());
	}
175854
public String toGeoJsonEnvelope(Envelope e) {
        return new StringBuffer().append("[").append(e.getMinX()).append(",")
                .append(e.getMinY()).append(",").append(e.getMaxX()).append(",")
                .append(e.getMaxY()).append("]").toString();
    }
504454
public UserCustomResultSet query(GeometryEnvelope envelope) {
		return query(envelope.getMinX(), envelope.getMinY(),
				envelope.getMaxX(), envelope.getMaxY());
	}
496114
def __geometryListToGeomTemplate(self, geometries):
        
        template = {"geometryType": None,
                    "geometries" : []}
        if isinstance(geometries, list) and len(geometries) > 0:
            for g in geometries:
                if isinstance(g, Polyline):
                    template['geometryType'] = "esriGeometryPolyline"
                elif isinstance(g, Polygon):
                    template['geometryType'] = "esriGeometryPolygon"
                elif isinstance(g, Point):
                    template['geometryType'] = "esriGeometryPoint"
                elif isinstance(g, MultiPoint):
                    template['geometryType'] = "esriGeometryMultipoint"
                elif isinstance(g, Envelope):
                    template['geometryType'] = "esriGeometryEnvelope"
                else:
                    raise AttributeError("Invalid geometry type")
                template['geometries'].append(g.asDictionary)
                del g
            return template
        return template
985933
public static GridCoverage2D buildDummyCoverage() {
        HashMap<String, Double> envelopeParams = new HashMap<String, Double>();
        envelopeParams.put(NORTH, 1.0);
        envelopeParams.put(SOUTH, 0.0);
        envelopeParams.put(WEST, 0.0);
        envelopeParams.put(EAST, 1.0);
        envelopeParams.put(XRES, 1.0);
        envelopeParams.put(YRES, 1.0);
        envelopeParams.put(ROWS, 1.0);
        envelopeParams.put(COLS, 1.0);
        double[][] dataMatrix = new double[1][1];
        dataMatrix[0][0] = 0;
        WritableRaster writableRaster = createWritableRasterFromMatrix(dataMatrix, true);
        return buildCoverage("dummy", writableRaster, envelopeParams, DefaultGeographicCRS.WGS84); //$NON-NLS-1$
    }