|
36 | 36 | import re
|
37 | 37 | import fnmatch
|
38 | 38 | import shutil
|
| 39 | +import subprocess |
39 | 40 | from typing import Optional, Dict, Union, Callable
|
40 | 41 | from collections import defaultdict
|
41 | 42 | from .Analyser_Osmosis import Analyser_Osmosis
|
@@ -731,15 +732,25 @@ def import_(self, table, osmosis):
|
731 | 732 | if info:
|
732 | 733 | self.zip = info.filename
|
733 | 734 |
|
| 735 | + source_layer = [ |
| 736 | + ('/vsizip/' if self.zip else '' ) + tmp_file.name + (('/' + self.zip) if self.zip else ''), |
| 737 | + ] |
| 738 | + if self.layer: |
| 739 | + source_layer.append(f"'{self.layer}'") |
| 740 | + |
| 741 | + s_src = re.search('EPSG:([0-9]+)', subprocess.run(["gdalsrsinfo", "-e", *source_layer], stdout=subprocess.PIPE).stdout.decode('utf-8')).group(1) |
| 742 | + wkt = PointInPolygon.PointInPolygon(self.polygon_id).polygon.as_wkt(s_src) if self.polygon_id else None |
| 743 | + |
734 | 744 | select = "-select '{}'".format(','.join(self.fields)) if self.fields else ''
|
735 |
| - gdal = "ogr2ogr -f PostgreSQL 'PG:{}' -lco SCHEMA={} -nln '{}' -lco OVERWRITE=yes -lco GEOMETRY_NAME=geom -lco OVERWRITE=YES -lco LAUNDER=NO -skipfailures {} -t_srs EPSG:{} '{}' {}".format( |
| 745 | + gdal = "ogr2ogr -f PostgreSQL 'PG:{}' -lco SCHEMA={} -nln '{}' {} -lco OVERWRITE=yes -lco GEOMETRY_NAME=geom -lco OVERWRITE=YES -lco LAUNDER=NO -skipfailures {} -t_srs EPSG:{} '{}' {}".format( |
736 | 746 | osmosis.config.osmosis_manager.db_string,
|
737 | 747 | osmosis.config.osmosis_manager.db_user,
|
738 | 748 | table,
|
| 749 | + f"-clipsrc '{wkt}'" if wkt else '', |
739 | 750 | select,
|
740 | 751 | self.proj,
|
741 |
| - ('/vsizip/' if self.zip else '' ) + tmp_file.name + (('/' + self.zip) if self.zip else ''), |
742 |
| - f"'{self.layer}'" if self.layer else '', |
| 752 | + source_layer[0], |
| 753 | + source_layer[1] if len(source_layer) >= 2 else '', |
743 | 754 | )
|
744 | 755 | print(gdal)
|
745 | 756 | if os.system(gdal):
|
@@ -1168,6 +1179,7 @@ def init(self, url, name, parser, load = Load(), conflate = Conflate()):
|
1168 | 1179 | self.conflate.select.tags = [self.conflate.select.tags]
|
1169 | 1180 | self.conflate.mapping.eval_static(self)
|
1170 | 1181 |
|
| 1182 | + self.parser.polygon_id = self.config.polygon_id |
1171 | 1183 | self.load.osmosis = self
|
1172 | 1184 | self.load.polygon_id = self.config.polygon_id
|
1173 | 1185 | if "proj" in self.config.options:
|
|
0 commit comments