Forums

Enabling GEOS for GDAL/OGR

Hey everyone,

I've created a web app to create sample plots from an input shapefile over at elza.pythonanywhere.com which functions mostly as expected.

The problem I am having is that as part of my python script the OGR function "intersects" is used. The function works, but it is not rigorous, meaning it only checks if the envelopes intersect. In order to rigorously check intersection, i.e., using geometries not envelopes, GEOS needs to be enabled. Check out the OGR Intersects help page here to read more about what I mean.

To visually show what I mean look at the following images: With GEOS | Without GEOS

GEOS stands for Geometry Engine Open Source. You can read more about it here. It complements the already installed GDAL/OGR packages by making them more powerful.

I know adding items to the site wide batteries included is a large endeavor, but I would like to pose GEOS as a candidate because without it OGR is much less useful.

Thanks guys,

Hayden

We already have GEOS installed. I don't know enough about GEOS and GDAL and OGR to work out why it's not working for you. Perhaps there's some documentation you can point us to that would help us understand.

Hey glenn,

I've finally had chance to try and isolate the problem.

To reproduce the error try running this in a python 2.7 console:

from osgeo import ogr

wkt1 = "POLYGON ((1208064.271243039 624154.6783778917, 1208064.271243039 601260.9785661874, 1231345.9998651114 601260.9785661874, 1231345.9998651114 624154.6783778917, 1208064.271243039 624154.6783778917))"
wkt2 = "POLYGON ((1199915.6662253144 633079.3410163528, 1199915.6662253144 614453.958118695, 1219317.1067437078 614453.958118695, 1219317.1067437078 633079.3410163528, 1199915.6662253144 633079.3410163528)))"

poly1 = ogr.CreateGeometryFromWkt(wkt1)
poly2 = ogr.CreateGeometryFromWkt(wkt2)

intersection = poly1.Intersection(poly2)

It should return this error:

ERROR 6: GEOS support not enabled.

As you have said before, you have GEOS installed. So I would guess the problem is that OGR was not built with geos. The basic process to build OGR/GDAL with GEOS and python bindings is as follows:

first install geos library (libgeos, libgeos-dev)

then download gdal source and configure it:

./configure --with-python -with-geos=yes

then

make

sudo make install

I copied those instructions from here about mid way down the page.

I hope this helps. If you have more questions about GEOS, GDAL, or OGR let me know and I'll do my best to help out. So far I really like the site and would love to host web apps here, though no geos support in ogr would be a deal breaker.

Thanks again for all your help!

Thanks @elza. It looks like our GDAL build doesn't have the --with-geos=yes flag, so that could definitely be it. We'll try and schedule an update to the library during our next standard server image build, but it's hard to say how soon that might come through...

Hi all,

I was wondering whether there are any updates on configuring OGR/GDAL with GEOS? I have built an app that cuts a Shapefile but it does not work on Pythonanywhere with out the GEOS support. I get the error mentioned above "ERROR 6: GEOS support not enabled."

Kind regards, John

Unfortunately no updates. I've upvoted the ticket on our to-do list on your behalf, but it's still quite low down the list :-(

I would love this to be updated as well

upvoted! no ETA yet I'm afraid.

Hello all, I am trying to re-prject a netCDF file with the following commands:

  1. gdal_translate -a_scale 0.000002 -a_offset 0.05 -a_nodata -32767 HDF5:"input.nc"://geophysical_data/Rrs_655 output13.tif

  2. gdalwarp output13.tif outfile2.tif -t_srs "+proj=longlat +ellps=WGS84"

However, the final output that I am receiving is a black with nodata values -32767. Can someone please suggest something. Any kind of help is appreciated.

Thank you!

NPal

It might be worth asking about that on Stack Overflow.

Hi! I've just tried to open all python consoles and type

from osgeo import ogr

but I received ImportError/ModuleNotFoundError.

What's wrong with it? Do I have to enable the package in someway?

Thanks a lot

Manuele

osgeo only supports up to Python 2.7 so it is only installed for Python 2.7.

I am using python 3.8 in my virtualenv. I need to use

from osgeo import gdal

How to get it. Thanks

As it's provided by the GDAL package nowadays, try running pip install GDAL in your virtualenv; that should pull down the most recent version, which should work with Python 3.8.

I tried pip install GDAL

comes with the following error

$ pip install GDAL
Looking in links: /usr/share/pip-wheels
Collecting GDAL
  Using cached GDAL-3.3.0.tar.gz (743 kB)
Building wheels for collected packages: GDAL
  Building wheel for GDAL (setup.py) ... error

Is there any more to the error message? Normally it would display some details about what that error is.

I have the same problem. I tried pip install gdal the I get a big message error, this is just a very small part:

Looking in links: /usr/share/pip-wheels
Collecting gdal
Downloading GDAL-3.3.0.tar.gz (743 kB)
   |████████████████████████████████| 743 kB 16.6 MB/s 
Building wheels for collected packages: gdal
Building wheel for gdal (setup.py) ... error
ERROR: Command errored out with exit status 1:
 command: /home/giosite/.virtualenvs/ve/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-hikibwbr/gdal_dc6a324db17a427286bb404d027af175/setup.py'"'"'; __file__='"'"'/tmp/pip-install-hikibwbr/gdal_dc6a324db17a427286bb404d027af175/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-j4hob37b
     cwd: /tmp/pip-install-hikibwbr/gdal_dc6a324db17a427286bb404d027af175/
Complete output (1898 lines):
WARNING: numpy not available!  Array support will not be enabled
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/osgeo
copying osgeo/ogr.py -> build/lib.linux-x86_64-3.8/osgeo
copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.8/osgeo
copying osgeo/utils.py -> build/lib.linux-x86_64-3.8/osgeo
copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.8/osgeo
copying osgeo/gdal.py -> build/lib.linux-x86_64-3.8/osgeo
copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.8/osgeo
copying osgeo/osr.py -> build/lib.linux-x86_64-3.8/osgeo
copying osgeo/__init__.py -> build/lib.linux-x86_64-3.8/osgeo
copying osgeo/gnm.py -> build/lib.linux-x86_64-3.8/osgeo
creating build/lib.linux-x86_64-3.8/osgeo_utils
copying gdal-utils/osgeo_utils/pct2rgb.py -> build/lib.linux-x86_64-3.8/osgeo_utils
copying gdal-utils/osgeo_utils/gdalmove.py -> build/lib.linux-x86_64-3.8/osgeo_utils
copying gdal-utils/osgeo_utils/ogrmerge.py -> build/lib.linux-x86_64-3.8/osgeo_utils
copying gdal-utils/osgeo_utils/gdal_retile.py -> build/lib.linux-x86_64-3.8/osgeo_utils
copying gdal-utils/osgeo_utils/gdal_merge.py -> build/lib.linux-x86_64-3.8/osgeo_utils
copying gdal-utils/osgeo_utils/gdal_sieve.py -> build/lib.linux-x86_64-3.8/osgeo_utils
copying gdal-utils/osgeo_utils/gdalcompare.py -> build/lib.linux-x86_64-3.8/osgeo_utils

(...)

please help, How to install GDAL in pythonanywhere?

[formatted by admin]

What's at the end of the error message?

this is the end part:

  extensions/gdal_array_wrap.cpp:4522:34: error: GDALExtendedDataTypeHS was not declared in this scope
 static bool CheckNumericDataType(GDALExtendedDataTypeHS* dt)
                                  ^
extensions/gdal_array_wrap.cpp:4522:58: error: dt was not declared in this scope
 static bool CheckNumericDataType(GDALExtendedDataTypeHS* dt)
                                                          ^
extensions/gdal_array_wrap.cpp:4523:1: error: expected , or ; before { token
 {
 ^
extensions/gdal_array_wrap.cpp:3514:13: warning: void _StoreLastException() defined but not used [-Wunused-function]
 static void _StoreLastException()
             ^
In file included from /home/giosite/.virtualenvs/ve/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:21:0,
                 from /home/giosite/.virtualenvs/ve/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from extensions/gdal_array_wrap.cpp:3539:
/home/giosite/.virtualenvs/ve/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1464:1: warning: int _import_array() def

ined but not used [-Wunused-function] _import_array(void) ^ extensions/gdal_array_wrap.cpp:4492:1: warning: ‘int CreateCIntListFromSequence(PyObject, int)’ defined but not used [-Wunused-function] CreateCIntListFromSequence( PyObject pySeq, int pnSize ) { ^ extensions/gdal_array_wrap.cpp:4522:13: warning: ‘CheckNumericDataType’ defined but not used [-Wunused-variable] static bool CheckNumericDataType(GDALExtendedDataTypeHS dt) ^ error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Command errored out with exit status 1: /home/giosite/.virtualenvs/ve/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '" '"'/tmp/pip-install-re097rnq/gdal_be72526bd4064fc78fb121f7a4d0c311/setup.py'"'"'; file='"'"'/tmp/pip-install-re097rnq/gdal_be72526bd4064fc78fb12 1f7a4d0c311/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(com pile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-7hhxrp0i/install-record.txt --single-version-externally-managed --compile -- install-headers /home/giosite/.virtualenvs/ve/include/site/python3.8/GDAL Check the logs for full command output.

i created a python env then I tried: pip install GDAL. But I get that error. In windows is hard to install. I though to install on a Linux machine will be easier.

There will be a new system image with the new gdal preinstalled available soon on PythonAnywhere.

good to know, thanks!

We will let you know!

It's been released :-) If you upgrade to our new Glastonbury system image (see here for details) you'll get the latest GDAL.

thank you very much. I installed GDAL. In my case: pip install GDAL==3.2.1 (python 3.8)

Thanks for letting us know!

Hola GDAL esta disponible en pythonanyhere? Pues al hacer python -c "import osgeo.ogr" obtengo ModuleNotFoundError: No module named 'osgeo' Usando pip install GDAL==3.2.1

Is osgeo something that you need to pip install?