37 votes

Using OSGeo4W shell with Python 3

There's no need to edit batch files (and break python 2.7 in the process) or set environment variables manually. Just run py3_env which sets the shell up for Python 3 automatically, then run python3. ...
user2856's user avatar
  • 64.9k
18 votes
Accepted

Using OSGeo4W shell with Python 3

There is a not well documented command build into OSGeo4W Shell which sets the shell up to python3 as Luke mentions py3_env Basically it sets your PYTHONHOME and the correct PATH. Then you can call ...
bennos's user avatar
  • 2,069
16 votes
Accepted

Differences between OSGEO GDAL and GDAL python bindings?

As documented in https://pypi.org/project/GDAL/ plain "gdal" is deprecated and you should not use that for writing any new code Additionally, there are five compatibility modules that are ...
user30184's user avatar
  • 63.3k
13 votes
Accepted

Getting bounding box from Point type GeoDataFrame to getting data from Osmnx

You can use the total_bounds property for this. Small example: In [83]: from shapely.geometry import Point In [84]: import geopandas In [86]: import random In [87]: df = geopandas.GeoDataFrame({'...
joris's user avatar
  • 3,863
12 votes
Accepted

Merging a geodataframe and pandas dataframe based on a column

You should specify a common key using on parameter. I removed merged_ prefix for legibility. df = spatial_df.merge(tab_df, on='mukey', how='left') # df = tab_df.merge(spatial_df, on='mukey', how='...
Kadir Şahbaz's user avatar
11 votes
Accepted

Split the column into several and unpivot the columns

You can use "Split features by character" tool. uri = r"C:\impression_plan\mini\RSFFicheCanalisation.shp" layer = QgsVectorLayer(uri, "", "ogr") new_layer = ...
Kadir Şahbaz's user avatar
10 votes
Accepted

Fill color not showing appropriately in folium?

According the documentation, when you're creating a CircleMarker object the fill parameter defaults to False. Try explicitly setting it to True in your code: #... for lt, ln, el in zip(lat, lon, ...
Ali's user avatar
  • 4,025
9 votes
Accepted

Python shapely intersection with buffer in meter

Shapely knows nothing about your units. Therefore, when you call polygon.buffer(0.2), shapely will buffer the coordinates in polygon by 0.2 units. In your case, these are not meters, but degrees. If ...
Jon's user avatar
  • 2,884
8 votes

Python 3 support in QGIS?

Python 3.6 has landed in QGIS 2.99:
underdark's user avatar
  • 83.9k
8 votes

Using OSGeo4W shell with Python 3

If you want to make the change permanent you can modify the batch file OSGeo4W.bat located in your QGIS (or OSGEO) directory and just add: call "py3_env" below the line calling call "%~dp0\bin\...
brodegon's user avatar
  • 351
8 votes
Accepted

Ipyleaflet map object doesn't display in Jupyter Notebook but it gets created

I just tried to install ipyleaflet with Jupyter 5.2.3: conda install -c conda-forge ipyleaflet and also didn't get a map. I then tried registering the extension with: jupyter nbextension enable --...
Marc Pfister's user avatar
  • 4,097
7 votes
Accepted

Using output statistics in ArcGIS REST API query?

The statistics you need are the count of OBJECTID for each DFIRM_ID, so your onStatisticField should be OBJECTID instead of DFIRM_ID. The groupBy parameter should be set to DFIRM_ID: [{ "...
Berend's user avatar
  • 4,597
7 votes
Accepted

Why does osr.SpatialReference return different values in python2 and 3?

The projections differ in the datum shift values for the conversion from Amersfoort datum to WGS84. The first one is tfm code 4833, and the second is tfm code 15934. GDAL 2.1.0 uses tfm code 4833, ...
AndreJ's user avatar
  • 76.5k
7 votes

Click event on maps with Folium and information retrieval

Actually I have found a great way to do it.. Folium has a feature named LatLngPopUp which creates a popup where you click on the map with its location. I've edited that popup and added a href link ...
Tal's user avatar
  • 71
7 votes
Accepted

Explaining pyproj to_epsg min_confidence parameter?

This is a great question and I will do my best to answer. To begin, the init style syntax is deprecated (https://pyproj4.github.io/pyproj/stable/gotchas.html#init-auth-auth-code-should-be-replaced-...
snowman2's user avatar
  • 7,191
7 votes
Accepted

QGIS 3 move layer to group

If you look at the API, the findGroup() method need a String "name value" but findLayer() need a Layer Id not the name. Then to make it work you need this: from qgis.core import QgsLayerTreeGroup, ...
Fran Raga's user avatar
  • 7,808
7 votes
Accepted

Converting ArcGIS Spatially Enabled Dataframe to GeoJSON

Neither the API documentation nor dir(pd.DataFrame.spatial) has any indication that there is a to_geojson() method. So there is no direct way to do this as far as I know. However, instead of using ...
Thomas's user avatar
  • 1,695
6 votes

Zonal Statistics of a polygon and assigning mean value to the polygon

There is a zonal statistics example in the Python GDAL/OGR Cookbook 1.0 documentation. This recipe calculates statistics on values of a raster within the zones of a vector dataset. It returns ...
Aaron's user avatar
  • 51.5k
6 votes
Accepted

Starting Python Shell Window of IDLE for use with ArcGIS Pro?

You can start the Python IDLE GUI from the Start Menu using the ArcGIS Pro Python command prompt. Start Menu > All Programs > ArcGIS > ArcGIS Pro > Python Command Prompt This will open a command ...
Midavalo's user avatar
  • 29.6k
6 votes

Smoothing shapefiles using Python

This solution worked for me. Just adjust the buffer amount to work with your units. Solution copied here: polygon.buffer(10, join_style=1).buffer(-10.0, join_style=1)
Riebeckite's user avatar
6 votes
Accepted

geoserver.catalog.FailedRequestError: Tried to make a GET request to http://localhost:8080/geoserver/workspaces.xml but got a 404 status code

It appears that gsconfig-py3 is less relaxed about the format of the base URL than gsconfig was. If it doesn't end / it doesn't think to add one for you. so cat = Catalog("http://localhost:8080/...
Ian Turton's user avatar
  • 80.5k
6 votes
Accepted

Polygon from QgsPoints - QGIS 3.8 python

In the line of the @BERA comment, this solves the problem in QGIS 3.8: The points must be created with 'QgsPointXY' (instead of 'QgsPoint'). The polygon must be created with 'fromPolygonXY' (instead ...
César Arquero Cabral's user avatar
6 votes
Accepted

Adding compression to a NetCDF file using xarray

The error hints at xarray trying to find a variable called "zlib" in your data. The correct structure for the encoding dict would be something like: encode = {"precipitation": {'...
bugmenot123's user avatar
  • 10.8k
5 votes

geopandas can't import

Had the same problem and ended with installing python3 with anaconda, and then installed geopandas with conda install -c conda-forge geopandas conda-forge is community curated packaging for python ...
MikolajM's user avatar
  • 151
5 votes
Accepted

How to let ogr/gdal CreateLayer() create a `geom` field instead of `wkb_geometry`?

As you can see from http://gdal.org/python/osgeo.ogr.DataSource-class.html#CreateLayer, CreateLayer support also "options" which are "None" by default. The papszOptions argument can be used to ...
user30184's user avatar
  • 63.3k
5 votes

Using OSGeo4W shell with Python 3

Please make sure that py3_env to initiate the python with OSGEO Shell is not working. The right command is pythonw if you have the current version of QGIS (3.20).
Chandrama Sarker's user avatar
5 votes

ArcPy Calculate Field Management with Variable

Your expression shouldn't include variable names. You're writing: "(+DemoField+ * !TractPercent!) / !BufferPOP!" but it should be: "(!{}! * !TractPercent!) / !BufferPOP!".format(DemoField.name)
Tom's user avatar
  • 4,118
5 votes
Accepted

Visualizing GPS points on interactive map

You can visualize your data on a map using folium. Please visit Documentation. (You must also have/install jupyter package. Installing Jupyter Notebook) Then this script displays your data on an ...
Kadir Şahbaz's user avatar
5 votes
Accepted

Get xy coordinates of QgsMapCanvas in PyQGIS 3?

You don't need to define lambda function and to specify self.canvas.scale() and self.canvas.xyCoordinates(). Because scaleChanged event passes scale and xyCoordinates passes coordinates to the related ...
Kadir Şahbaz's user avatar
5 votes
Accepted

Write a Spatial Join output to a CSV?

You are including the geometries as text in the csv which can slow down the export since each vertice is written as text. If you dont need them use drop: merged_gdf.drop('geometry',axis=1).to_csv(r'...
BERA's user avatar
  • 68.9k

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