32
votes
Transforming Shapely Polygon and MultiPolygon objects
If you're using pyproj2, it's much easier to use a Transformer. Here's an example:
import pyproj
from shapely.ops import transform
project = pyproj.Transformer.from_proj(
pyproj.Proj(init='epsg:...
20
votes
Converting projected coordinates to lat/lon using Python
When using pyproj, note the differences from various releases in how it is used to transform data. Here are a few examples using new/old capabilities based on the question:
Using pyproj >= 2.2.0
...
16
votes
Accepted
Convert GPS coordinates to Web Mercator EPSG:3857 using python/pyproj
from pyproj import Proj, transform
print(transform(Proj(init='epsg:4326'), Proj(init='epsg:3857'), -0.1285907, 51.50809)) # longitude first, latitude second.
# output (meters east of 0, meters north ...
16
votes
Vertical Datum transformation using Pyproj
The accepted answer has a couple of flaws I'd like to address.
First, the objection to the use of NAD83 is misplaced. It is true that NAD83 is a horizontal datum, but the setup in the question uses ...
14
votes
UserWarning when trying to get centroid from a polygon GeoPandas
Round-trip the data through a flat projection, ideally one which preserves area, such as Equal Area Cylindrical ('+proj=cea'):
df1.to_crs('+proj=cea').centroid.to_crs(df1.crs)
This projects the ...
13
votes
Accepted
Converting shapefile from projected coordinates using pyproj and fiona
At the first question, 'epsg:32054' code has feet units. For this reason, it is necessary to use 'preserve_units=True' as parameter in inProj = Proj(init='epsg:32054') line. Now, next code works well:
...
13
votes
Accepted
Convert GPS coordinates into 3-dimensional cartesian coordinates (x,y,z)
To do 3D transformations, you need 3D CRS:
EPSG:4326 (2D) -> EPSG:4979 (3D)
<Geographic 3D CRS: EPSG:4979>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- ...
11
votes
Accepted
Different origins of UTM projection
Both coordinates are the same. As you are in the Southern Hemisphere a False Northing (of +10000000m) is usually applied to eliminate the negatives.
The utm package applies the false Northing by ...
11
votes
Accepted
Constant future warnings with new pyproj
The +init=epsg:xxxx syntax (or in form of a {'init': 'epsg:xxx'}) is being deprecated in PROJ / pyproj (see here. You are indeed not using it directly, but, the previous releases of GeoPandas (<= 0....
11
votes
I am getting the wrong result for north coordinate
It might be related to the proj string you specified. Use CRS instead of the proj string.
from pyproj import Proj, CRS
#converting lat/long - UTM
lat = -22.818009494
long = -47.059235202
crs = CRS....
10
votes
Accepted
Use pyproj new projection initialization method when setting a CRS in GeoPandas
'<authority>:<code>' in the error means that you need just to use crs='EPSG:4326' instead of crs={'epsg:4326'}.
9
votes
Converting EPSG:2284 to EPSG:4326 with pyproj
Simply use (Converting elevations into correct units with pyproj?, Proj4 String for NAD83(2011) / Louisiana South (ftUS), ...)
preserve_units=True (as you say, pyproj assumes that your coordinates ...
9
votes
Accepted
Using Rioxarray / QGIS Projection
Upon inspecting the dataset, I realized that the units of the data are in radians.
import xarray
import rioxarray
from pyproj import CRS
xds = xarray.open_dataset("OR_ABI-L2-LSTF-...
8
votes
Why does Pyproj fail converting lon lat alt to ECEF?
Probably because in
lon, lat, alt = 49.74761271, -113.2179781, 0
a lat of -113.2179781 is outside the valid bounds of -90 to 90.
8
votes
Converting WGS84 to ECEF in Python?
Here is a test(seems both methods work with same precision):
import math
import pyproj
coords = [
(37.4001100556, -79.1539111111, 208.38),
(37.3996955278, -79.153841, 208.48),
(37....
8
votes
Python pyproj converting from wgs84 to Israel Grid IG 05/12 EPSG:6991
The proj4 library has an error identifying the difference between Israel TM Grid 2039 and IG 05/12 6991. Survey if Israel made a horrendous error and updated 2039 to include the new 7 parameter ...
8
votes
Converting projected coordinates to lat/lon using pyproj fails
If you examine the answer of afalciano in Converting projected coordinates to lat/lon using Python?
1) you define the two projections
# original projection
p = pyproj.Proj("+proj=stere +lat_0=90 +...
8
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-...
8
votes
Accepted
UserWarning when trying to get centroid from a polygon GeoPandas
I am no expert on geopandas, but to me the warning only tells you that you should use a crs with coordinates in meters,
Probably because the function calculating the centroid doesn't support ...
8
votes
I am getting the wrong result for north coordinate
The issue is the stray comma and unnecessary latitude band K. With the proj string, +zone= must be a value between 1-60, so just use 23 without a comma:
myProj = Proj("+proj=utm +zone=23 +south +...
7
votes
Converting projected coordinates to lat/lon using Python
Tried the code suggested by Marcel Wilson and it is faster:
from pyproj import Proj, transform
import time
import pyproj
# Test 1 - 0.0006158 s
start=time.time()
inProj = Proj(init='epsg:3857')
...
7
votes
Change shapefile coordinate system using Python
Here's some handy code from the Python GDAL/OGR cookbook that will reproject a shapefile.
from osgeo import ogr, osr
import os
in_epsg = 5514
out_epsg = 4326
in_shp = '/path/to/input.shp'
out_shp = '/...
7
votes
Accepted
Converting EPSG:2263 to WGS84 using Python Pyproj
Look Converting EPSG:2284 to EPSG:4326 with pyproj (and many others...).
Pyproj expects degrees (lon, lat) or meters (x,y) as units but the unit of Projection: 2263 isUNIT["US survey foot"..., ...
7
votes
Converting large data with lat and long into X and Y?
UPDATE:
After thinking about it, the most efficient method for you to transform the coordinates is probably to not use apply but to use the column array.
from pyproj import Proj
pp = Proj(proj='utm',...
7
votes
Accepted
Transformation from CRS EPSG:3857 to ESRI:54009
Your output CRS is not defined by EPSG but by ESRI. EPSG:54009 does not exist. For ESRI:54009 use ImportFromESRI https://gdal.org/python/osgeo.osr.SpatialReference-class.html#ImportFromESRI.
EDIT
User ...
6
votes
Change shapefile coordinate system using Python
Here is even more concise option using geopandas library:
import geopandas
data = geopandas.read_file(path+file_in)
# change CRS to epsg 4326
data = data.to_crs(epsg=4326)
# write shp file
data....
6
votes
Setting CRS to ESRI:102001 using GeoPandas
The +init= syntax is deprecated. So all you need is the ESRI:102001 part. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#init-auth-auth-code-should-be-replaced-with-auth-auth-code
inputGDF....
6
votes
Accepted
What is the correct way to assign GeoPandas a CRS from Rasterio?
You should try to preserve the WKT form if possible. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems
It all depends on the version of geopandas.
...
6
votes
Use pyproj new projection initialization method when setting a CRS in GeoPandas
As too often, I continue cobbling around with my code after having posted my question, and I figure it out:
Short
Do not pass a dictionary but a string as a CRS!
Explanation
I.e, in concrete ...
6
votes
Accepted
Setting CRS of point using shapely
Shapely geometries are unaware of their CRS. Using pyproj to transform them only changes the values of the coordinates without leaving any trace of the final CRS in the resulting geometries. ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pyproj × 303python × 177
coordinate-system × 152
proj × 59
geopandas × 28
shapely × 24
wgs84 × 21
epsg × 17
gdal × 16
utm × 16
coordinates × 13
latitude-longitude × 13
qgis × 10
python-3 × 10
convert × 9
rasterio × 7
shapefile × 6
fiona × 6
ellipsoid × 6
rioxarray × 6
vertical-transformation × 6
geometry × 5
netcdf × 4
well-known-text × 4
transform × 4