26

it looks like a silly question, yet I can't find clear answer on that: what units geopandas/shapely use calculating distance/area between objects?

underdark
  • 84,148
  • 21
  • 231
  • 413
Philipp_Kats
  • 1,964
  • 3
  • 18
  • 21

3 Answers3

22

Shapely uses a cartesian plane system for computing geometries (distance = euclidean distance)

Shapely does not support coordinate system transformations. All operations on two or more features presume that the features exist in the same Cartesian plane.

GeoPandas uses Fiona to read shapefiles (and others) and Pyproj for cartographic transformations.

The coordinate reference system (CRS) of the collection’s vector data is accessed via a read-only crs attribute.

import fiona
c = fiona.open("test.shp")
print c.crs['units']
m

The unit for calculating distance/area between objects with Shapely is meter in this case.

It is the same with GeoPandas

import geopandas as gp
df = gp.GeoDataFrame.from_file('test.shp')
print df.crs['units']
m

That means that if you work with a crs.unit = degree (WGS84 for example) all calculations are wrong.You must first reproject you layer (How do I convert Eastings and Northings projection to WSG84 in geopandas? )

pathmapper
  • 1,985
  • 14
  • 22
gene
  • 54,868
  • 3
  • 110
  • 187
  • 2
    Does anything change when you load from PostGIS instead? I am setting the coordinates as an argument when calling read_postgis the resulting data frame only has attribute crs, which is a string. It does not have attribute crs['units']; attempting to request that results in a TypeError. – kuanb Feb 10 '17 at 19:20
  • 5
    For 2020, in Geopandas you must use df.crs.axis_info[0].unit_name to get the units that are being used. – ndw May 07 '20 at 21:33
  • 2
    @gene Would you be able to update your answer to include using df.crs.axis_info[0].unit_name from the comments? df.crs['units'] must be obsolete now. Many thanks! – Aaron Feb 02 '21 at 03:48
4

Whichever units are represented by the coordinates in your geometries.

Shapely geometries are Cartesian and make no assumptions about being Lon/Lat or anything else.

jakew
  • 171
  • 2
0

For Geopandas, it depends of the assigned Coordinate Reference System to the GeoDataFrame.

For shapely its in the same units of the cartesian plane, shapely does not support CRS source.

pablete
  • 101