Skip to content

Commit

Permalink
Merge pull request #2802 from Geoportail-Luxembourg/fix_api_print
Browse files Browse the repository at this point in the history
Manage esri polygon with holes
  • Loading branch information
rmichaelis authored Oct 13, 2021
2 parents edb2d56 + 14602bc commit 18e6a18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 40 deletions.
48 changes: 8 additions & 40 deletions geoportal/geoportailv3_geoportal/views/getfeatureinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from shapely.ops import transform
from shapely.wkt import loads as wkt_loads
from functools import partial
from arcgis2geojson import arcgis2geojson

from geoportailv3_geoportal.lib.esri_authentication import ESRITokenException
from geoportailv3_geoportal.lib.esri_authentication import get_arcgis_token, read_request_with_token
Expand Down Expand Up @@ -1308,7 +1309,10 @@ def _get_external_data(self, layer_id, url, id_column='objectid',
try:
url_request = urllib.request.Request(query_count)
result = read_request_with_token(url_request, self.request, log)
self.content_count = geojson_loads(result.data)['count']
geojson_res = geojson_loads(result.data)
self.content_count = 0
if 'count' in geojson_res:
self.content_count = geojson_res['count']
except ESRITokenException as e:
log.exception(e)
log.error(url)
Expand Down Expand Up @@ -1340,45 +1344,9 @@ def _get_external_data(self, layer_id, url, id_column='objectid',
'coordinates': [[
[x1, y1], [x2, y1], [x2, y2], [x1, y2], [x1, y1]
]]}
elif (rawfeature['geometry'] and
'x' in rawfeature['geometry'] and
'y' in rawfeature['geometry']):
geometry = {'type': 'Point',
'coordinates': [rawfeature['geometry']['x'],
rawfeature['geometry']['y']]}
elif (rawfeature['geometry'] and
'x' in rawfeature['geometry'] and
'Y' in rawfeature['geometry']):
geometry = {'type': 'Point',
'coordinates': [rawfeature['geometry']['x'],
rawfeature['geometry']['Y']]}
elif (rawfeature['geometry'] and
'paths' in rawfeature['geometry'] and
len(rawfeature['geometry']['paths']) > 0):
geometry = {'type': 'MultiLineString',
'coordinates': rawfeature['geometry']['paths']}
elif (rawfeature['geometry'] and
'rings' in rawfeature['geometry'] and
len(rawfeature['geometry']['rings']) > 0):
if len(rawfeature['geometry']['rings']) == 1:
geometry = {'type': 'Polygon',
'coordinates':
rawfeature['geometry']['rings']}
else:
coordinates = []
curpolygon = []
for ring in rawfeature['geometry']['rings']:
if not LinearRing(ring).is_ccw:
if len(curpolygon) > 0:
coordinates.append(curpolygon)
curpolygon = []
curpolygon.append(ring)

if len(curpolygon) > 0:
coordinates.append(curpolygon)

geometry = {'type': 'MultiPolygon',
'coordinates': coordinates}
else:
geojsonrawfeature = arcgis2geojson(rawfeature)
geometry = geojsonrawfeature['geometry']

if geometry != '':
alias = {}
Expand Down
1 change: 1 addition & 0 deletions geoportal/luxembourg_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ pyramid_assetviews==1.0a3
transifex-client
pyyaml
gdal==2.2
arcgis2geojson==2.0.1

0 comments on commit 18e6a18

Please sign in to comment.