mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-10 12:00:21 +08:00
Add testing for read_postgis function
It also installs postgis and creates a simple database filled with the borough data. A new requirements.test.txt file is created so that not everybody installing geopandas is required to install the packages for testing, psycopg2 in this case.
This commit is contained in:
+11
-1
@@ -10,10 +10,20 @@ env:
|
||||
before_install:
|
||||
- sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install gdal-bin libgdal-dev
|
||||
- sudo apt-get install gdal-bin libgdal-dev postgresql-9.1-postgis-2.0
|
||||
- sudo -u postgres psql -c "drop database if exists test_geopandas"
|
||||
- sudo -u postgres psql -c "create database test_geopandas"
|
||||
- sudo -u postgres psql -c "create extension postgis" -d test_geopandas
|
||||
- ogrinfo --version
|
||||
- ogrinfo --formats
|
||||
- wget http://www.nyc.gov/html/dcp/download/bytes/nybb_13a.zip
|
||||
- unzip nybb_13a.zip
|
||||
- sudo -u postgres ogr2ogr -nlt MULTIPOLYGON -f "PostgreSQL" PG:"user=postgres dbname=test_geopandas" -lco PRECISION=NO -lco GEOMETRY_NAME="geom" nybb_13a/nybb.shp
|
||||
|
||||
|
||||
install:
|
||||
- pip install -r requirements.txt --use-mirrors
|
||||
- pip install -r requirements.test.txt --use-mirrors
|
||||
- git clone git://github.com/pydata/pandas.git
|
||||
- cd pandas
|
||||
- git checkout $PANDAS_VERSION
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
psycopg2>=2.5.1
|
||||
@@ -7,6 +7,7 @@ import urllib2
|
||||
|
||||
import numpy as np
|
||||
from shapely.geometry import Point, Polygon
|
||||
import psycopg2
|
||||
|
||||
from geopandas import GeoDataFrame
|
||||
|
||||
@@ -82,3 +83,26 @@ class TestDataFrame(unittest.TestCase):
|
||||
lonlat = df2.to_crs(epsg=4326)
|
||||
utm = lonlat.to_crs(epsg=26918)
|
||||
self.assertTrue(all(df2['geometry'].almost_equals(utm['geometry'], decimal=2)))
|
||||
|
||||
def _validate_sql(self, df):
|
||||
# Make sure all the columns are there and the geometries
|
||||
# were properly loaded as MultiPolygons
|
||||
columns = ('borocode', 'boroname', 'shape_leng', 'shape_area')
|
||||
for col in columns:
|
||||
self.assertTrue(col in df.columns, 'Column {} missing'.format(col))
|
||||
self.assertTrue(all(df['geometry'].type == 'MultiPolygon'))
|
||||
|
||||
def test_read_postgis_default(self):
|
||||
con = psycopg2.connect(dbname='test_geopandas')
|
||||
sql = "SELECT * FROM nybb;"
|
||||
df = GeoDataFrame.read_postgis(sql, con)
|
||||
self._validate_sql(df)
|
||||
|
||||
def test_read_postgis_custom_geom_col(self):
|
||||
con = psycopg2.connect(dbname='test_geopandas')
|
||||
sql = """SELECT
|
||||
borocode, boroname, shape_leng, shape_area,
|
||||
geom AS __geometry__
|
||||
FROM nybb;"""
|
||||
df = GeoDataFrame.read_postgis(sql, con, geom_col='__geometry__')
|
||||
self._validate_sql(df)
|
||||
|
||||
Reference in New Issue
Block a user