Hot answers tagged

15

Demo: SOLUTION: This is a two-step solution, Step 1: Browser (JavaScript). It copies the popup text to the clipboard. Step 2: QGIS (Python). It gets the text from the clipboard, parses to obtain latitude and longitude, then adds the point to the active layer. In Browser: Open the website. Open DevTools Ctrl+Shift+C. Source > Snippets > New snippet &...


10

Here my solution, entirely in QGIS (version >= 3.14, for versions >= 3.0 and < 3.14, maybe few adjustments are needed). The solution is to create a points grid in QGIS and retrieve data from JavaScript functions and update each point. The entry parameters of the function are : QGIS interface iface The solar eclipse elements, you can find it in the ...


7

If you can retrieve the GeoJSON text in a Python object, you can execute the code below : # geoj is the string object that contains the GeoJSON geoj = """ { "type": "MultiLineString", "coordinates": [ [[10, 10], [20, 20], [10, 40]], [[40, 40], [30, 30], [40, 20], [30, 10]] ] } ""&...


6

Here is a simple OpenLayers example https://codesandbox.io/s/simple-forked-4m0d8 which will fetch a TrackID, convert the points, elevation and times into an XYZM format linestring and display it. HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Simple Map</title> ...


5

Several years later, this is still an issue with QGIS 3.16 Hanover. But a workaround exists (thank you, @gioman). When you export to geoJSON, specify a "Custom Option" with id_field=my_field: That saves the specified field as the geoJSON feature IDs. If your geoJSON already exists, you can move the ID from properties to its proper place using the ...


5

No need for QGIS here. Imagining you have a recent PostgreSQL and PostGIS 3+ (because of function ST_AsGeoJSON), in the command line, you can use the following psql -t test_postgis3 <<EOF > /tmp/out.geojson select json_build_object( 'type', 'FeatureCollection', 'features', json_agg(ST_AsGeoJSON(t.*)::json) ) from ( values (1, 'one', '{&...


5

GeoPandas is an addon to Pandas where a geometry column has special meaning and writing output writes geospatial file formats. If you want to export just the non-spatial data, the easiest way would be to create a plain Pandas DataFrame from your GeoDataframe, so the geometry column loses its special meaning, and then remove it. To do so in one "step&...


5

In The Shapely User Manual -> object.distance(other) Returns the minimum distance (float) to the other geometric object. from shapely.geometry import LineString l1 = LineString([(42.073407, -87.806245), (42.0752508,-87.8080299)]) from shapely.wkt import loads l2 = loads(" LINESTRING(35.442827 -79.470579, 35.444889 -79.469465, 35.445829 -79.468907, ...


5

The GeoJSON specification requires GeoJSON data to be EPSG:4326 (WGS 84). Your coordinates are not WGS 84. So you need to transform your data when creating the GeoJSON. Then you can just copy it into geojson.io and it will work fine. Note that some software (e.g. QGIS) are able to save GeoJSON in any coordinate system whatsoever. This is due to the ...


5

You need to set Layer Options > GEOMETRY to any option except <Default> in Save Vector Layer as... window.


5

With the command line, https://gdal.org/programs/gdal_rasterize.html With Python, you can use gdal.RasterizeLayer like in the tests from GDAL e.g https://github.com/OSGeo/gdal/blob/master/autotest/alg/rasterize.py With Java, you can use the same function from Java bindings https://github.com/OSGeo/gdal/blob/master/gdal/swig/java/javadoc.java#L733 (PS: ...


4

It was not clear to me how the features have to be split and saved, e.g. only selected or simply all. Hereupon I am providing several possibilities that may answer the question. Case 1. When certain features have to be selected and exported afterwards Check the following articles: How to Save a Selection as a New File Using QGIS Saving/exporting selected ...


4

If you create GeoJSON layer in Leaflet from GeoJSON file/object, you'll see that each Leaflet feature object gets feature property, which contains source GeoJSON object with all it's properties. If you create GeoJSON object from such layer with .toGeoJSON() method, you get initial GeoJSON object, again with all it's properties. Taking this into account when ...


3

You can use the -spat option of ogr2ogr and a loop to do this. On a linux box I'd do something like: for x in `seq -180 10 170`; do x2=$((x+10)) ogr2ogr -spat $x -90 $x2 90 -spat_srs epsg:4326 outfile_$x.json infile.shp done


3

I would recommend using GeoServer for this. It can generate tiles as geoJSON natively and can installed very easily, setting the GEOWEBCACHE_CACHE_DIR environment variable will let you choose where your cache of XYZ tiles will be genrated. You would need to add a data source from a folder of shapefiles, and then publish the layer from the file you want to ...


3

You can use rasterio.mask method: import fiona import rasterio import rasterio.mask with fiona.open("file.geojson", "r") as geojson: features = [feature["geometry"] for feature in geojson] with rasterio.open("file.tiff") as src: out_image, out_transform = rasterio.mask.mask(src, features, crop=True) out_meta ...


3

Based on J. Monticolo's answer I have modified his script. The first one is for python console and the second one a processing algorithm. Both will ignore features, that have an invalid GeoJSON-String as content. Script for Python-Console: # Define settings: source_layer = QgsProject.instance().mapLayersByName("mylayer")[0] # Define Source-layer ...


3

Using the generated geojson file, I noticed that it did not open, the name and description being under geometry. I applied the following modification: var lat = document.getElementById("a").value; var lng = document.getElementById("b").value; var name = document.getElementById("c").value; var description = document....


3

This is probably more of a question for stackoverflow directly, however if you are able to use ES6, you could use something like this: const filteredFeatures = kitespots.features.filter(item => { return item.properties.windDirection.split("/").includes("S"); }); The filter function will return merely those items which include S. ...


3

GeoJSON can have only one layer. https://tools.ietf.org/html/rfc7946#section-2 GeoJSON Text A GeoJSON text is a JSON text and consists of a single GeoJSON object. GeoJSON Object A GeoJSON object represents a Geometry, Feature, or collection of Features. For GDAL and QGIS this means https://gdal.org/drivers/vector/geojson.html A GeoJSON datasource is ...


3

In creating your GeoJSON, you forgot to add type property for your feature: "type" : "Feature", so it should be: { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "MultiPolygon", . . . That's ...


3

You can use the geometrygenerator to display parts of your multilinestring in different colors. With the expression: geometry_n($geometry,2) you will get the second part of the multilinestring. Then you can choose a color or special linestyle for that. see image below. It is one Multilinestring with 3 parts in different colors.


3

I'll just copy-paste my response to Leaflet bug #6173 : I'm reading the OGC's Simple Feature Access specification (again), to remind myself about the formal definitions of Polygons and MultiPolygons. Let me quote page 31: 6.1.14 MultiPolygon A MultiPolygon is a MultiSurface whose elements are Polygons. The assertions for MultiPolygons are as follows. a) The ...


3

The standard already allows you to add a bbox inside the feature collection. A GeoJSON object MAY have a member named "bbox" to include information on the coordinate range for its Geometries, Features, or FeatureCollections.


3

Ogr2ogr cannot be used for updating an existing layer. It is better not to try any tricks but simply convert GeoJSON data into a new file and after that delete the original file and rename the result file. Because GeoJSON is a text based format it must be re-written in any case so trying to do something more clever with updates in-place does not make sense, ...


3

Ogr2ogr is also available as a Python function VectorTranslate. No need to use subprocess. See the API documentation https://gdal.org/python/osgeo.gdal-module.html#VectorTranslate https://gdal.org/python/osgeo.gdal-module.html#VectorTranslateOptions Minimal usage example: from osgeo import gdal srcDS = gdal.OpenEx('test.json') ds = gdal.VectorTranslate('test....


3

Change your query. See https://overpass-turbo.eu/s/17Ng Then, you can export/ download as GEOJSON [out:json][timeout:25]; ( way(167047843); ); out body; >; out skel qt; You can also use this command line utility npm install -g query-overpass and then echo "[out:json][timeout:25]; ( way(167047843); ); out body; >; out skel qt; " | query-...


3

When you create marker cluster group from GeoJSON data that contains only points for markers, and you markers will be L.circleMarker markers, you must have the following in mind: You can use L.geoJSON for parsing GeoJSON data, creating desired markers and adding them to cluster, but you don't add GeoJSON layer to the map. Markers of type L.circleMarker are ...


3

You may try the following (tested) ogr2ogr -nln spatial.buildings -dialect SQLite -sql "SELECT geometry AS footprint FROM RhodeIsland" -update -append -gt 65536 -f "PostgreSQL" PG:"<my connection string>" "RhodeIsland.geojson" Using -sql and -dialect SQLite, you are able to remap geometry column correctly You ...


2

You can do full Transactional Editing of Data (WFS-T) you can output to multiple formats Check out the newer OGC API Features specification (it will basically become WFS 3.0 but it's using JSON instead of XML and has nicer interface and pages) Crunchy Data offers pg_featureserv or GeoServer has a Community Module/Extension Check out GeoJSON-VT for leaflet ...


Only top voted, non community-wiki answers of a minimum length are eligible