user2241910 - 8 months ago 54

Python Question

I have a GeoDataFrame with some polygons (from some County shape files).

`0 POLYGON ((-118.71455 46.822508, -118.67662 46....`

1 POLYGON ((-118.663169 47.043673, -118.66334 47...

2 POLYGON ((-118.484262 46.73667, -118.495995 46...

3 POLYGON ((-118.483051 46.839378, -118.482689 4...

4 POLYGON ((-118.82874 46.77891, -118.822177 46....

5 POLYGON ((-118.606476 46.96391999999999, -118....

I'm trying to do take some intersections of these polygons with some polygons in another GeoDataFrame (same state). The coordinates of the polygons, however, are completely different.

`0 POLYGON ((552346.2856999999 380222.8998000007,...`

1 POLYGON ((529754.7249999996 409135.9135999996,...

2 POLYGON ((552333.0957000004 371726.9315000009,...

3 POLYGON ((542734.0181999998 376530.5831000004,...

4 POLYGON ((552291.6204000004 362052.4251000006,...

They're the same state, and the plots look the same. I'm new to shapefiles, but think if I could "normalize" these polygons (divide all the points in the x dimension by their smallest value, same for the y dimension), then the polygons in the two DataFrames should be comparable.

I've tried:

`df.scale(origin=(1,1))`

and also

`df.scale(xfact=1.0/df.total_bounds[0], yfact=1.0/df.total_bounds[1])`

without any luck. They just return their original values (or close to, values should be between 1 and 2). I could loop through these polygons and unpack their points and divide them, but I am hoping there's a more elegant solution way.

Running the latest dev version of geopandas 0.1.0, python 2.7 (I know...time to move on), OSX.

Answer

You need to reproject or transform one of the geometries to a common coordinate reference system.

See documentation for `GeoSeries.to_crs(crs=None, epsg=None)`

to do this.

The first GeoDataFrame looks like EPSG:4326 (this is a guess, there are other geographic coordinate reference systems). The second is possibly a UTM or State plane projection.