geopandas error "minimums more than maximums"

For the benefit of anyone else searching for this error message, one thing that can cause it is attempting to do a spatial join where the point coordinates contain nulls.


There are many problems in your data (sample_map_data.csv) and in your script.

1) the sample_map_data.csv file contains 6 valid lines and 730 lines with ''

import pandas as pd  
points = pd.read_csv("sample_map_data.csv")
points.shape
(735, 3)

Resulting in the error "RTreeError: Coordinates must not have minimums more than maximums"

The right result should be .

points = pd.read_csv("sample_map_data.csv",nrows= 5)
points.shape
(5, 3)
print(points)
Latitude   Longitude  Heat
0  23.124700  113.282776   100
1  22.618574  113.999634    80
2  23.694332  113.049316    70
3  23.809973  114.735718    90
4  21.815098  110.961914    80)

2) In Shapely, a Point is defined by Point(x,y) and not Point(y,x) so

from shapely.geometry import Point
points['geometry'] = points.apply(lambda z: Point(z.Longitude, z.Latitude), axis=1)
import geopandas as gpd
PointsGeodataframe = gpd.GeoDataFrame(points)
print(PointsGeodataframe)
Latitude      Longitude    Heat         geometry
0  23.124700  113.282776   100  POINT (113.282776 23.1247)
1  22.618574  113.999634    80  POINT (113.999634 22.618574)
2  23.694332  113.049316    70  POINT (113.049316 23.694332)
3  23.809973  114.735718    90  POINT (114.735718 23.809973)
4  21.815098  110.961914    80  POINT (110.961914 21.815098)

3) For Points in Polygons, look at More Efficient Spatial join in Python without QGIS, ArcGIS, PostGIS, etc): no need of op='intersects'

PolygonsGeodataframe = gpd.GeoDataFrame.from_file("CHN_adm1.shp")
PointsGeodataframe.crs = PolygonsGeodataframe.crs #same crs for the two layers
from geopandas.tools import sjoin
pointInPolys = sjoin(PointsGeodataframe, PolygonsGeodataframe, how='left') 
print(pointInPolys.head(5))

and it works.