Convert Figma logo to code with AI

pyproj4 logopyproj

Python interface to PROJ (cartographic projections and coordinate transformations library)

1,052
211
1,052
33

Top Related Projects

1,702

PROJ - Cartographic Projections and Coordinate Transformations Library

Python tools for geographic data

3,832

Manipulation and analysis of geometric objects

4,430

Geocoding library for Python.

1,420

Cartopy - a cartographic python library with matplotlib support

1,042

Python interface to PROJ (cartographic projections and coordinate transformations library)

Quick Overview

PyProj is a Python library for performing cartographic transformations and geodetic computations. It provides a Pythonic interface to the PROJ library, allowing users to convert between different coordinate reference systems, perform datum transformations, and work with various map projections.

Pros

  • Powerful and flexible cartographic capabilities
  • Seamless integration with other geospatial Python libraries (e.g., GeoPandas, Shapely)
  • Supports both 2D and 3D coordinate transformations
  • Actively maintained and well-documented

Cons

  • Can be complex for beginners unfamiliar with geodetic concepts
  • Dependency on the PROJ library may cause installation issues on some systems
  • Performance may be slower compared to native C/C++ implementations for large datasets

Code Examples

  1. Converting coordinates from WGS84 to UTM Zone 33N:
from pyproj import Transformer

transformer = Transformer.from_crs("EPSG:4326", "EPSG:32633")
lat, lon = 52.5200, 13.4050
x, y = transformer.transform(lat, lon)
print(f"UTM coordinates: {x:.2f}, {y:.2f}")
  1. Creating a custom projection:
from pyproj import CRS

custom_proj = CRS.from_proj4("+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs")
print(custom_proj.to_wkt(pretty=True))
  1. Calculating geodesic distance between two points:
from pyproj import Geod

geod = Geod(ellps="WGS84")
lon1, lat1, lon2, lat2 = -0.1276, 51.5074, 2.3522, 48.8566  # London to Paris
distance = geod.inv(lon1, lat1, lon2, lat2)[2] / 1000  # Convert to km
print(f"Distance: {distance:.2f} km")

Getting Started

To install PyProj, use pip:

pip install pyproj

Basic usage example:

from pyproj import Transformer

# Create a transformer to convert from WGS84 to Web Mercator
transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True)

# Convert coordinates
lon, lat = -74.0060, 40.7128  # New York City
x, y = transformer.transform(lon, lat)
print(f"Web Mercator coordinates: {x:.2f}, {y:.2f}")

For more information, refer to the official documentation at https://pyproj4.github.io/pyproj/stable/.

Competitor Comparisons

1,702

PROJ - Cartographic Projections and Coordinate Transformations Library

Pros of PROJ

  • Written in C, offering potentially better performance for low-level operations
  • Broader scope, supporting more coordinate systems and transformation methods
  • Standalone library that can be used in various programming languages

Cons of PROJ

  • Steeper learning curve due to C API and more complex functionality
  • Requires separate installation and management of the PROJ library
  • Less Pythonic interface compared to PyProj

Code Comparison

PyProj:

from pyproj import Transformer

transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857")
x, y = transformer.transform(51.5074, -0.1278)

PROJ (using Python bindings):

from osgeo import osr

source = osr.SpatialReference()
source.ImportFromEPSG(4326)
target = osr.SpatialReference()
target.ImportFromEPSG(3857)
transform = osr.CoordinateTransformation(source, target)
x, y, _ = transform.TransformPoint(-0.1278, 51.5074)

PyProj is a Python wrapper for PROJ, offering a more Pythonic interface and easier integration with other Python libraries. It's generally easier to use for Python developers but may have slightly lower performance for certain operations. PROJ, being the underlying library, offers more flexibility and can be used in various programming environments beyond Python.

Python tools for geographic data

Pros of GeoPandas

  • Provides high-level geospatial data manipulation and analysis tools
  • Integrates well with pandas for working with tabular data
  • Supports various geospatial file formats (e.g., Shapefile, GeoJSON)

Cons of GeoPandas

  • Larger library with more dependencies, potentially slower for simple operations
  • Less focused on coordinate transformations compared to PyProj
  • May have a steeper learning curve for users unfamiliar with pandas

Code Comparison

PyProj example:

from pyproj import Transformer

transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857")
x, y = transformer.transform(51.5074, -0.1278)

GeoPandas example:

import geopandas as gpd

gdf = gpd.read_file("data.shp")
gdf_transformed = gdf.to_crs("EPSG:3857")

GeoPandas offers higher-level functionality for working with geospatial data, while PyProj focuses on coordinate transformations. GeoPandas is better suited for complex geospatial analysis tasks, while PyProj is more efficient for simple coordinate conversions.

3,832

Manipulation and analysis of geometric objects

Pros of Shapely

  • Focuses on geometric operations and manipulations
  • Provides a rich set of spatial analysis functions
  • Easier to use for basic geometric tasks

Cons of Shapely

  • Limited projection capabilities
  • Lacks advanced coordinate system transformations
  • Not optimized for large-scale geospatial data processing

Code Comparison

Shapely example:

from shapely.geometry import Point, Polygon

point = Point(0, 0)
polygon = Polygon([(0, 0), (1, 1), (1, 0)])
print(polygon.contains(point))

PyProj example:

from pyproj import Transformer

transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857")
lon, lat = -74.0, 40.7
x, y = transformer.transform(lon, lat)
print(x, y)

Shapely excels in geometric operations and spatial analysis, making it easier for basic geometric tasks. However, it has limited projection capabilities compared to PyProj. PyProj, on the other hand, specializes in coordinate system transformations and is better suited for handling complex projection tasks and large-scale geospatial data processing.

4,430

Geocoding library for Python.

Pros of geopy

  • Higher-level abstraction for geocoding and distance calculations
  • Supports multiple geocoding services out of the box
  • Easier to use for common geospatial tasks

Cons of geopy

  • Limited functionality for coordinate system transformations
  • Less suitable for advanced geodetic operations
  • Slower performance for large-scale calculations

Code Comparison

geopy example:

from geopy.distance import geodesic
newport_ri = (41.49008, -71.312796)
cleveland_oh = (41.499498, -81.695391)
print(geodesic(newport_ri, cleveland_oh).miles)

pyproj example:

from pyproj import Geod
g = Geod(ellps='WGS84')
lon1, lat1, lon2, lat2 = -71.312796, 41.49008, -81.695391, 41.499498
az12, az21, dist = g.inv(lon1, lat1, lon2, lat2)
print(f"Distance: {dist/1000:.2f} km")

geopy is more straightforward for simple distance calculations, while pyproj offers more control and is better suited for complex geodetic operations.

1,420

Cartopy - a cartographic python library with matplotlib support

Pros of Cartopy

  • More comprehensive mapping and visualization capabilities
  • Built-in support for various map projections and coordinate systems
  • Integrates well with Matplotlib for creating publication-quality maps

Cons of Cartopy

  • Steeper learning curve due to more complex API
  • Heavier dependency footprint, including GEOS and Shapely
  • May be overkill for simple coordinate transformations

Code Comparison

Cartopy example:

import cartopy.crs as ccrs
import matplotlib.pyplot as plt

ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
plt.show()

Pyproj example:

from pyproj import Transformer

transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857")
x, y = transformer.transform(51.5074, -0.1278)

Cartopy is better suited for creating maps and visualizations, while Pyproj excels at coordinate transformations and geodetic calculations. Cartopy offers a higher-level interface for mapping tasks, whereas Pyproj provides more low-level control over projections and transformations. Choose Cartopy for comprehensive mapping projects and Pyproj for specific coordinate system operations or when working with other geospatial libraries.

1,042

Python interface to PROJ (cartographic projections and coordinate transformations library)

Pros of pyproj

  • More active development and frequent updates
  • Larger community and better documentation
  • Supports both Python 2 and 3

Cons of pyproj

  • Slightly more complex API for some operations
  • Larger package size due to additional features

Code Comparison

pyproj:

from pyproj import Transformer

transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857")
x, y = transformer.transform(51.5074, -0.1278)

pyproj>:

from pyproj import Proj, transform

p1 = Proj("EPSG:4326")
p2 = Proj("EPSG:3857")
x, y = transform(p1, p2, -0.1278, 51.5074)

Both repositories provide similar functionality for coordinate transformations and projections. pyproj offers a more modern API with the Transformer class, while pyproj> uses the older transform function. The main difference lies in the order of coordinates passed to the transformation function.

pyproj is generally recommended for new projects due to its active development and broader feature set. However, pyproj> may be suitable for simpler use cases or maintaining compatibility with older codebases.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Pyproj logo

pyproj

Python interface to PROJ (cartographic projections and coordinate transformations library).

Join the chat at https://gitter.im/pyproj4-pyproj/community All Contributors Appveyor Build Status GitHub Actions Build Status Codecov Status PyPI Downloads Anaconda-Server Badge Code style: black pre-commit DOI

Documentation

Bugs/Questions

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Jeff Whitaker

📖 ⚠️ 💻 💡 🤔 👀 💬 🚧 🚇 🐛

Alan D. Snow

📖 ⚠️ 💻 💡 🚧 🚇 🤔 👀 💬 🐛

Micah Cochran

📖 ⚠️ 💻 🚧 🚇 👀 💬 🐛

Joris Van den Bossche

📖 💻 🤔 👀 💬 🐛 ⚠️

Chris Mayo

⚠️

Charles Karney

💻 ⚠️

Justin Dearing

🚇

Jos de Kloe

💻 ⚠️ 🐛

George Ouzounoudis

💻 🤔

David Hoese

👀 🤔 📦 📖 ⚠️ 💻

Mikhail Itkin

💻

Ryan May

💻

artttt

🤔

Filipe

🚇 💻 📦 📖

Heitor

📖

Bas Couwenberg

💻 📦 ⚠️

Nick Eubank

💻

Michael Dunphy

📖

Matthew Brett

🚇 📦

Jakob de Maeyer

💻

The Gitter Badger

📖

Bernhard M. Wiedemann

💻

Marco Aurélio da Costa

💻

Christopher H. Barker

💻

Kristian Evers

💬 🤔 📖

Even Rouault

💬

Christoph Gohlke

📦 💬 🐛 ⚠️

Chris Willoughby

💻

Guillaume Lostis

📖

Eduard Popov

📖

Joe Ranalli

🐛 💻 ⚠️

Greg Berardinelli

🐛 💻 🤔 ⚠️

Martin Raspaud

🐛 💻 ⚠️ 🤔

Mike Taves

⚠️

David Haberthür

📖

mmodenesi

🐛 💻 ⚠️

jacob-indigo

🐛 💻

Poruri Sai Rahul

⚠️

Yann-Sebastien Tremblay-Johnston

📖

odidev

📦

Idan Miara

💻 📖 💡 ⚠️

Brendan Jurd

📖 🎨

Bill Little

📖

Gerrit Holl

📖

Kirill Kouzoubov

💻

Dan Hemberger

🐛 💻

Martin Fleischmann

🐛 💻 ⚠️

Matthias Meulien

💻 🐛

Isaac Boates

💻 🐛 ⚠️

Kyle Penner

💻 🐛 📖

paulcochrane

💻 📖 ⚠️ 🐛

Antonio Ettorre

📦

DWesl

💻

Víctor Molina García

📦

Samuel Kogler

🐛 💻

Alexander Shadchin

🐛 💻

Greg Lucas

💻 🤔

Dan Mahr

💻 📖 ⚠️

Romain Hugonnet

💻 📖 ⚠️

Javier Jimenez Shaw

💻 📖 ⚠️

Daniel McDonald

📖

Cora Schneck

📖 ⚠️

zanejgr

📖

This project follows the all-contributors specification. Contributions of any kind welcome!