Skip to content

Commit

Permalink
Merge pull request #286 from Toblerity/rbuffat-newgdal2
Browse files Browse the repository at this point in the history
René Buffat's gdal2 v2 revised
  • Loading branch information
sgillies committed Oct 27, 2015
2 parents 68d271c + 9984947 commit 3ebef78
Show file tree
Hide file tree
Showing 12 changed files with 1,691 additions and 22 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IDE's etc.
.idea/
venv/
venv2/

#fiona
fiona/ogrext.c
fiona/_drivers.c
fiona/_err.c
fiona/_geometry.c
fiona/_transform.cpp
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ before_install:
- export LD_LIBRARY_PATH=$GDALINST/gdal-$GDALVERSION/lib:$LD_LIBRARY_PATH

install:
- "pip install -r requirements.txt"
- "pip install -r requirements-dev.txt"
- "pip install pytest"
- "pip install coveralls"
Expand All @@ -41,5 +42,6 @@ env:

matrix:
- GDALVERSION="1.9.2"
- GDALVERSION="1.11.2"
# - GDALVERSION="2.0.0"
- GDALVERSION="1.11.3"
- GDALVERSION="2.0.0"
- GDALVERSION="2.0.1"
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ gdal``).
Python Requirements
-------------------

Fiona depends on the modules ``six``, ``cligj``, ``argparse``, and
Fiona depends on the modules ``six``, ``cligj``, ``future``, ``munch``, ``argparse``, and
``ordereddict`` (the two latter modules are standard in Python 2.7+). Pip will
fetch these requirements for you, but users installing Fiona from a Windows
installer must get them separately.
Expand Down Expand Up @@ -320,7 +320,7 @@ locations on your system (via your system's package manager), you can do this::
If you have a non-standard environment, you'll need to specify the include and
lib dirs and GDAL library on the command line::

(fiona_env)$ python setup.py build_ext -I/path/to/gdal/include -L/path/to/gdal/lib -lgdal develop
(fiona_env)$ python setup.py build_ext -I/path/to/gdal/include -L/path/to/gdal/lib -lgdal --gdalversion 2.0.1 develop
(fiona_env)$ nosetests

.. _OGR: http://www.gdal.org/ogr
Expand Down
File renamed without changes.
185 changes: 185 additions & 0 deletions fiona/ograpi2.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Copyright (c) 2007, Sean C. Gillies
# All rights reserved.
# See ../LICENSE.txt

cdef extern from "gdal.h":
char * GDALVersionInfo (char *pszRequest)
void * GDALGetDriverByName(const char * pszName)
void * GDALOpenEx(const char * pszFilename,
unsigned int nOpenFlags,
const char ** papszAllowedDrivers,
const char ** papszOpenOptions,
const char *const *papszSibling1Files
)
int GDAL_OF_UPDATE
int GDAL_OF_READONLY
int GDAL_OF_VECTOR
int GDAL_OF_VERBOSE_ERROR
int GDALDatasetGetLayerCount(void * hds)
void * GDALDatasetGetLayer(void * hDS, int iLayer)
void * GDALDatasetGetLayerByName(void * hDS, char * pszName)
void GDALClose(void * hDS)
void * GDALGetDatasetDriver(void * hDataset)
void * GDALCreate(void * hDriver,
const char * pszFilename,
int nXSize,
int nYSize,
int nBands,
GDALDataType eBandType,
char ** papszOptions)
void * GDALDatasetCreateLayer(void * hDS,
const char * pszName,
void * hSpatialRef,
int eType,
char ** papszOptions)
int GDALDatasetDeleteLayer(void * hDS, int iLayer)
void GDALFlushCache(void * hDS)
char * GDALGetDriverShortName(void * hDriver)
char * GDALGetDatasetDriver (void * hDataset)


ctypedef enum GDALDataType:
GDT_Unknown
GDT_Byte
GDT_UInt16
GDT_Int16
GDT_UInt32
GDT_Int32
GDT_Float32
GDT_Float64
GDT_CInt16
GDT_CInt32
GDT_CFloat32
GDT_CFloat64
GDT_TypeCount

cdef extern from "gdal_version.h":
int GDAL_COMPUTE_VERSION(int maj, int min, int rev)

cdef extern from "cpl_conv.h":
void * CPLMalloc (size_t)
void CPLFree (void *ptr)
void CPLSetThreadLocalConfigOption (char *key, char *val)
const char *CPLGetConfigOption (char *, char *)

cdef extern from "cpl_string.h":
char ** CSLSetNameValue (char **list, char *name, char *value)
void CSLDestroy (char **list)

cdef extern from "cpl_vsi.h":
ctypedef struct VSILFILE:
pass
int VSIFCloseL (VSILFILE *)
VSILFILE * VSIFileFromMemBuffer (const char * filename,
unsigned char * data,
int data_len,
int take_ownership)
int VSIUnlink (const char * pathname)

ctypedef int OGRErr
ctypedef struct OGREnvelope:
double MinX
double MaxX
double MinY
double MaxY

cdef extern from "ogr_core.h":
char * OGRGeometryTypeToName(int)

cdef extern from "ogr_srs_api.h":
void OSRCleanup ()
void * OSRClone (void *srs)
void OSRDestroySpatialReference (void *srs)
int OSRExportToProj4 (void *srs, char **params)
int OSRExportToWkt (void *srs, char **params)
int OSRImportFromEPSG (void *srs, int code)
int OSRImportFromProj4 (void *srs, char *proj)
int OSRSetFromUserInput (void *srs, char *input)
int OSRAutoIdentifyEPSG (void *srs)
int OSRFixup(void *srs)
const char * OSRGetAuthorityName (void *srs, const char *key)
const char * OSRGetAuthorityCode (void *srs, const char *key)
void * OSRNewSpatialReference (char *wkt)
void OSRRelease (void *srs)
void * OCTNewCoordinateTransformation (void *source, void *dest)
void OCTDestroyCoordinateTransformation (void *source)
int OCTTransform (void *ct, int nCount, double *x, double *y, double *z)

cdef extern from "ogr_api.h":
char * OGR_Dr_GetName (void *driver)
void * OGR_Dr_CreateDataSource (void *driver, const char *path, char **options)
int OGR_Dr_DeleteDataSource (void *driver, char *)
void * OGR_Dr_Open (void *driver, const char *path, int bupdate)
void * OGR_F_Create (void *featuredefn)
void OGR_F_Destroy (void *feature)
long OGR_F_GetFID (void *feature)
int OGR_F_IsFieldSet (void *feature, int n)
int OGR_F_GetFieldAsDateTime (void *feature, int n, int *y, int *m, int *d, int *h, int *m, int *s, int *z)
double OGR_F_GetFieldAsDouble (void *feature, int n)
int OGR_F_GetFieldAsInteger (void *feature, int n)
char * OGR_F_GetFieldAsString (void *feature, int n)
int OGR_F_GetFieldCount (void *feature)
void * OGR_F_GetFieldDefnRef (void *feature, int n)
int OGR_F_GetFieldIndex (void *feature, char *name)
void * OGR_F_GetGeometryRef (void *feature)
void OGR_F_SetFieldDateTime (void *feature, int n, int y, int m, int d, int hh, int mm, int ss, int tz)
void OGR_F_SetFieldDouble (void *feature, int n, double value)
void OGR_F_SetFieldInteger (void *feature, int n, int value)
void OGR_F_SetFieldString (void *feature, int n, char *value)
int OGR_F_SetGeometryDirectly (void *feature, void *geometry)
void * OGR_FD_Create (char *name)
int OGR_FD_GetFieldCount (void *featuredefn)
void * OGR_FD_GetFieldDefn (void *featuredefn, int n)
int OGR_FD_GetGeomType (void *featuredefn)
char * OGR_FD_GetName (void *featuredefn)
void * OGR_Fld_Create (char *name, int fieldtype)
void OGR_Fld_Destroy (void *fielddefn)
char * OGR_Fld_GetNameRef (void *fielddefn)
int OGR_Fld_GetPrecision (void *fielddefn)
int OGR_Fld_GetType (void *fielddefn)
int OGR_Fld_GetWidth (void *fielddefn)
void OGR_Fld_Set (void *fielddefn, char *name, int fieldtype, int width, int precision, int justification)
void OGR_Fld_SetPrecision (void *fielddefn, int n)
void OGR_Fld_SetWidth (void *fielddefn, int n)
OGRErr OGR_G_AddGeometryDirectly (void *geometry, void *part)
void OGR_G_AddPoint (void *geometry, double x, double y, double z)
void OGR_G_AddPoint_2D (void *geometry, double x, double y)
void OGR_G_CloseRings (void *geometry)
void * OGR_G_CreateGeometry (int wkbtypecode)
void OGR_G_DestroyGeometry (void *geometry)
unsigned char * OGR_G_ExportToJson (void *geometry)
void OGR_G_ExportToWkb (void *geometry, int endianness, char *buffer)
int OGR_G_GetCoordinateDimension (void *geometry)
int OGR_G_GetGeometryCount (void *geometry)
unsigned char * OGR_G_GetGeometryName (void *geometry)
int OGR_G_GetGeometryType (void *geometry)
void * OGR_G_GetGeometryRef (void *geometry, int n)
int OGR_G_GetPointCount (void *geometry)
double OGR_G_GetX (void *geometry, int n)
double OGR_G_GetY (void *geometry, int n)
double OGR_G_GetZ (void *geometry, int n)
void OGR_G_ImportFromWkb (void *geometry, unsigned char *bytes, int nbytes)
int OGR_G_WkbSize (void *geometry)
OGRErr OGR_L_CreateFeature (void *layer, void *feature)
int OGR_L_CreateField (void *layer, void *fielddefn, int flexible)
OGRErr OGR_L_GetExtent (void *layer, void *extent, int force)
void * OGR_L_GetFeature (void *layer, int n)
int OGR_L_GetFeatureCount (void *layer, int m)
void * OGR_L_GetLayerDefn (void *layer)
char * OGR_L_GetName (void *layer)
void * OGR_L_GetNextFeature (void *layer)
void * OGR_L_GetSpatialFilter (void *layer)
void * OGR_L_GetSpatialRef (void *layer)
void OGR_L_ResetReading (void *layer)
void OGR_L_SetSpatialFilter (void *layer, void *geometry)
void OGR_L_SetSpatialFilterRect (
void *layer, double minx, double miny, double maxx, double maxy
)
int OGR_L_TestCapability (void *layer, char *name)
void * OGRGetDriverByName (char *)
void * OGROpen (char *path, int mode, void *x)
void * OGROpenShared (char *path, int mode, void *x)
int OGRReleaseDataSource (void *datasource)
OGRErr OGR_L_SetNextByIndex (void *layer, long nIndex)
long long OGR_F_GetFieldAsInteger64 (void *feature, int n)
void OGR_F_SetFieldInteger64 (void *feature, int n, long long value)
8 changes: 2 additions & 6 deletions fiona/ogrext.pyx → fiona/ogrext1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ OGRERR_FAILURE = 6
OGRERR_UNSUPPORTED_SRS = 7
OGRERR_INVALID_HANDLE = 8

# Recent versions of OGR can sometimes detect file encoding, but don't
# provide access yet to the detected encoding. Hence this variable.
OGR_DETECTED_ENCODING = '-ogr-detected-encoding'


def _explode(coords):
"""Explode a GeoJSON geometry's coordinates object and yield
Expand Down Expand Up @@ -433,7 +429,7 @@ cdef class Session:
self._fileencoding = (
ograpi.OGR_L_TestCapability(
self.cogr_layer, OLC_STRINGSASUTF8) and
OGR_DETECTED_ENCODING) or (
'utf-8') or (
self.get_driver() == "ESRI Shapefile" and
'ISO-8859-1') or locale.getpreferredencoding().upper()

Expand Down Expand Up @@ -728,7 +724,7 @@ cdef class WritingSession(Session):
userencoding = self.collection.encoding
self._fileencoding = (userencoding or (
ograpi.OGR_L_TestCapability(self.cogr_layer, OLC_STRINGSASUTF8) and
OGR_DETECTED_ENCODING) or (
'utf-8') or (
self.get_driver() == "ESRI Shapefile" and
'ISO-8859-1') or locale.getpreferredencoding()).upper()

Expand Down
Loading

0 comments on commit 3ebef78

Please sign in to comment.