diff --git a/.travis.yml b/.travis.yml index f080112..66165a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/requirements.test.txt b/requirements.test.txt new file mode 100644 index 0000000..7f762a0 --- /dev/null +++ b/requirements.test.txt @@ -0,0 +1 @@ +psycopg2>=2.5.1 diff --git a/tests/test_geodataframe.py b/tests/test_geodataframe.py index a8615b1..5477c27 100644 --- a/tests/test_geodataframe.py +++ b/tests/test_geodataframe.py @@ -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)