Hot answers tagged

8 votes
Accepted

Unable to remove GeoJSON features/layer in Leaflet

One way of solving this problem would be to declare geojson variable global outside getParkingLots function. Then layer has to be created only the first time, and from then on it just has to be ...
  • 20.7k
7 votes
Accepted

Converting Pandas column with featurecollection to GeoJSON

You can use the following code. Just specify json_string_column and output file path. import json import pandas as pd import geopandas as gpd # df = YOUR DATAFRAME json_string_column = "...
6 votes

Inserting polygon as GeoJSON in PostGIS with only boundry coordinates

PostGIS has no concept of GeoJSON - except for the I/O functionality, which translates between the internal and the GeoJSON representation of geometric features. Likewise does your exemplary input not ...
  • 27.2k
5 votes

'ValueError: Expected object or value' when reading GeoJSON file with Pandas

There are several things to keep in mind: Do not forget to close the GeoJSON with ]} There is no need to call the read_json() via pd.io.json.read_json, simply pd.read_json. Even if it is placed in ...
  • 28.1k
5 votes
Accepted

What URL to use when exporting data from an ArcGIS MapServer layer to GeoJSON using ogr2ogr?

ogr2ogr -f GeoJSON test.json "https://kart.ra.no/arcgis/rest/services/Distribusjon/Kulturminner20180301/MapServer/6/query?where=1=1&outFields=*&outSR=4326&f=geojson" OGRGeoJSON
  • 12.7k
5 votes
Accepted

Crossing lines when displaying multilinestring from GeoJSON in Leaflet

I managed to partly resolve the mystery of GeoJSON returned by WFS service. There are still some coordinates missing, but that's probably consequence of some configuration error on GeoServer. First I ...
  • 20.7k
5 votes
Accepted

Create layer from an array of geometries in OpenLayers?

You will need an array of features, not just geometries. Create features containing the identifying properties of each ope, then read the geometry into OpenLayers format and set it in the feature. ...
  • 11.5k
4 votes

Is there any efficient way to convert GeoJSON to WKT?

I know this is old, but this question comes up highly when looking for ways to make OGR2OGR output as WKT and no one has specifically answered how to do that: As of GDAL/OGR 1.6.0 it is possible to ...
  • 291
4 votes
Accepted

What's wrong with this geojson file?

A valid GeoJSON is only in EPSG:4326. Your file is in EPSG:25830. You can set the CRS when you export the file in QGIS.
  • 8,466
4 votes
Accepted

"KeyError: 0" when calculating area of polygon using GeoPandas

The usual way to calculate area and store it as a new column (attribute) is: df["area"] = df.area but you might see a useful warning: UserWarning: Geometry is in a geographic CRS. Results ...
  • 41.1k
4 votes
Accepted

Labeling GeoJSON polylines in Leaflet

To position tooltip above, you have to use direction: 'top' tooltip option. To get rid of callout and for other tooltip style adjustments, just modify appropriate Leaflet CSS styles. For example, with ...
  • 20.7k
4 votes

Generating unique positive integers as id with ogr2ogr

You can also achieve it with GeoPandas using the index=None: bool parameter If True, write index into one or more columns (for MultiIndex). Default None writes the index into one or more columns only ...
  • 28.1k
4 votes
Accepted

Generating unique positive integers as id with ogr2ogr

Note: if you have id among your properties, and you prefer to preserve it there, see this answer instead: https://gis.stackexchange.com/a/449190/191643 Using this answer to the question How to ...
4 votes
Accepted

Convert ESRI JS Graphic geometry into WKT format

You can use arcgis-to-geojson-utils library (see https://github.com/Esri/arcgis-to-geojson-utils) to convert ESRI JSON to GeoJSON, and then terraformer/wkt library (see https://github.com/terraformer-...
  • 20.7k
3 votes

Loading JSON data into QGIS

For the Capital Regional District (CRD) Basemap you can use: https://mapservices.crd.bc.ca/arcgis/rest/services/ In QGIS you can use the ArcGIS Rest Services Connection.
  • 49.2k
3 votes
Accepted

Using GeoJSON as input to leaflet.motion plugin in Leaflet

All you have to do is extract line string coordinates from geoJsonData and store them in some array, let's say dataCoords, and flip coordinates while doing that, since Leaflet expects [lat, lng] ...
  • 20.7k
3 votes
Accepted

Folium draw and highlight polylines with distinct colours from unique GeoJSON

Solution (works perfectly)! It appears it is possible to achieve what I set to (see main question) within the extent of the style_function. We can pass values to the style_function properties in a ...
3 votes
Accepted

Extract shapes and shape data from GeoTIFF using Rasterio and store as GeoJSON

shapes returns an iterable of tuples with geometry and value, you can use geopandas to parse the geometry into a valid geojson. import geopandas as gpd import rasterio from rasterio import features ...
  • 58.7k
3 votes
Accepted

'NameError: name 'importos' is not defined' when loading GeoJSON file QGIS

I could get the same error: Traceback (most recent call last): File "C:\PROGRA~1\QGIS32~1.5\apps\Python39\lib\code.py", line 90, in runcode exec(code, self.locals) File "<...
  • 28.1k
3 votes
Accepted

Checking intersection between polygon and geometry in GeoJSON

Shapely use (x,y) in the geometries and not (y,x), therefore: polygon_geom = Polygon(zip(lon_point_list,lat_point_list)) df1 = gpd.GeoDataFrame({'geometry':[polygon_geom]}) for geo in df["...
  • 53.4k
3 votes
Accepted

Set linestring color by property value in PyQGIS

You can can set a data-defined-property for your line stroke color without iterating over every feature. I tested this on a temporary scratch layer. It should work fine for you. Select your layer as ...
  • 18.3k
3 votes
Accepted

Turf area function gives different area than QGIS

Probably you are affected by this bug. turf.area uses an earth radius value different that other software like PostGIS. There is a fix in the repo but seems not to be available in the last published ...
3 votes

ValueError: Invalid coordinate dimensionality

With your script the result of list_lines is a string, and you cannot create a shapely MultiLineString with strings a) With a simple list of WKT strings (and not a string with lists): from shapely....
  • 53.4k
3 votes
Accepted

Convert a WKT string within a text file to GeoJSON using ogr2ogr or GDAL command line tools

Read some documentation https://gdal.org/drivers/vector/csv.html. Edit the text file and add a header line and enclose the WKT between double quotation marks. Notice ending comma in the header. It is ...
  • 59.2k
3 votes
Accepted

How to choose a GeoJSON file and load it into OpenLayers

You could drag and drop the file as in https://openlayers.org/en/latest/examples/drag-and-drop.html Otherwise add a file input element to your HTML: <input type="file" id="input-file&...
  • 11.5k
3 votes
Accepted

Update a Mapbox layer by zoom level when loading geojson

First you would need to flatten your data into single-geometry features as one feature has multi-geometry. Then you can dissolve your data into a second Feature Collection based on the propertyName ...
  • 2,076
3 votes
Accepted

Accessing all features of vector layer (GeoJSON) in OpenLayers?

Since you are loading GeoJSON from web, operation is async, which means you have to wait till features are loaded before you try to use them. To detect when features are loaded you can use layer ...
  • 20.7k
3 votes
Accepted

Update a choropleth layer by zoom level when using a GeoJSON in Mapbox

It works perfectly well, you just have to give different ids to your two GeoJSON layers: map.addLayer({ 'id': 'Ghana1', 'type': 'fill', 'source': 'Ghana', 'maxzoom': zoomThreshold, 'paint': {...
  • 20.7k
3 votes

Why doesn't ogr2ogr's -nln flag have any effect on output GeoJSON in some cases?

From the GeoJSON spec: https://www.rfc-editor.org/rfc/rfc7946 6.1. Foreign Members Members not described in this specification ("foreign members") MAY be used in a GeoJSON document. ...
  • 9,111
3 votes

Why doesn't ogr2ogr's -nln flag have any effect on output GeoJSON in some cases?

I believe that you have found a bug. If you convert GeoJSON data that has already name set, then ogr2ogr does not change the name even if the option -nln is used. The name is set as an optional ...
  • 59.2k

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