GeoDjango GEOSException error

故事扮演 提交于 2019-11-28 15:47:01
nachopro

This is my solution (obviously it is ugly, like my English, but works). The problem is that the versions string has an white space unwanted in the RegEx.

The error says:

GEOSException: Could not parse version info string "3.4.2-CAPI-1.8.2 r3921"

And the geos_version_info warns:

Regular expression should be able to parse version strings such as '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1' or '3.4.0dev-CAPI-1.8.0'

Edit this file: site-packages/django/contrib/gis/geos/libgeos.py

Look for the function: geos_version_info

And change this line:

ver = geos_version().decode()

With this line:

ver = geos_version().decode().split(' ')[0]

In the latest GEOS install, the above answer didn't work... but was close to the problem.

I changed the regex right above the geos_version_info(): from:

version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)$')

to be:

version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+).*$')

Notice the .* added to the end of the regex.

I think this is broken again. A recent upgrade on our FreeBSD server led to this error:

django.contrib.gis.geos.error.GEOSException: Could not parse version info string "3.6.2-CAPI-1.10.2 4d2925d6"

Looks like the regex in Django's libgeos.py needs to be updated again to account for this different syntax. Nachopro's solution still serves as a workaround.

It appears that this has been fixed in Django as of last March or so. See also Django bug 20036. So upgrading to Django 1.5.4 will solve the problem.

For those folks who don't have 3.6.1 previously installed:

  1. brew unlink geos
  2. Install 3.6.1 with brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/145b22e8330e094ee148861e72e26c03e73d34a1/Formula/geos.rb.
  3. brew info geos should show 3.6.1 starred:

This can be fixed by trying the following,

brew switch geos 3.6.1

I fixed the issue by installing PostGIS with Postgres using https://postgresapp.com/downloads.html.

  1. Install PostGIS (2.2): brew install postgis
  2. To unlink geos if version is higher than 3.6.1: brew unlink geos
  3. Install Geos (3.6.1): brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/145b22e8330e094ee148861e72e26c03e73d34a1/Formula/geos.rb
  4. Switch geos version(latest version is 3.7.2 which is not supported by Django 1.11.3): brew switch geos 3.6.1
  5. Login to database and create postgis extensions: CREATE EXTENSION postgis; Test postgis extension: SELECT ST_Distance('LINESTRING(-122.33 47.606, 0.0 51.5)'::geography, 'POINT(-21.96 64.15)'::geography);
  6. Check postgis version: SELECT PostGIS_full_version();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!