Exemplo n.º 1
0
    def __coord_transform__(self, coord, source_crs):
        """
        Transforms the specified coordinates from the specified CRS to the configured target
        CRS and creates a point geometry.

        Args:
            coord (tuple): The coordinates to transform (x, y).
            source_crs (intorstr): The source CRS

        Returns:
            shapely.geometry.Point or shapely.geometry.Polygon: The transformed coordinates as
            Point.
        """
        log.debug('----- Transforming Coordinates: -----')
        log.debug('----- X/Y Coordinates: {0} -----'.format(coord))
        epsg = 'epsg:{0}'
        srid = Config.get('srid')
        log.debug('----- srid from config (to_srs): {0} -----'.format(srid))
        log.debug(
            '----- srid from source (from_srs): {0} -----'.format(source_crs))
        rp = Reprojector()
        x, y = rp.transform(coord,
                            from_srs=epsg.format(source_crs),
                            to_srs=epsg.format(srid))
        log.debug(
            '----- X/Y coordinates after transformation: ({0}, {1}) -----'.
            format(x, y))
        return Point(x, y)
Exemplo n.º 2
0
 def __init__(self,
              session,
              model,
              geometry_type,
              srid,
              arc_max_diff=0.001,
              arc_precision=3):
     self._session = session
     self._model = model
     self._geometry_type = geometry_type
     self._to_srs = srid
     self._arc_max_diff = arc_max_diff
     self._arc_precision = arc_precision
     self._log = logging.getLogger('import_federal_topic')
     self._reprojector = Reprojector()
Exemplo n.º 3
0
    def read(self, street_name, zip_code, street_number):
        """
        Queries an address using the federal GeoAdmin API location search.

        Args:
            street_name (unicode): The name of the street for the desired address.
            zip_code (int): The postal zipcode for the desired address.
            street_number (unicode): The house or so called street number of the desired address.
        """
        headers = {
            'Referer':
            'http://bl.ch'  # TODO: Remove this header when referer is not needed anymore!
        }
        params = {
            'type':
            self._type,
            'origins':
            self._origins,
            'searchText':
            u'{0} {1} {2}'.format(zip_code, street_name, street_number)
        }
        response = requests.get(self._geoadmin_url,
                                params=params,
                                proxies=self._proxies,
                                headers=headers)
        if response.status_code == requests.codes.ok:
            rp = Reprojector()
            srid = Config.get('srid')
            self.records = list()
            data = response.json()
            if 'results' in data:
                for item in data.get('results'):
                    attrs = item.get('attrs')
                    if isinstance(attrs,
                                  dict) and attrs.get('origin') == 'address':
                        x, y = rp.transform(
                            (attrs.get('lon'), attrs.get('lat')), to_srs=srid)
                        self.records.append(
                            AddressRecord(street_name=street_name,
                                          zip_code=zip_code,
                                          street_number=street_number,
                                          geom='POINT({x} {y})'.format(x=x,
                                                                       y=y)))
        else:
            response.raise_for_status()
Exemplo n.º 4
0
    def __coord_transform__(self, coord, source_crs):
        """
        Transforms the specified coordinates from the specified CRS to the configured target CRS and creates a
        point geometry.

        Args:
            coord (tuple): The coordinates to transform (x, y).
            source_crs (intorstr): The source CRS

        Returns:
            shapely.geometry.Point or shapely.geometry.Polygon: The transformed coordinates as
            Point.
        """
        epsg = 'epsg:{0}'
        srid = Config.get('srid')
        rp = Reprojector()
        x, y = rp.transform(coord, from_srs=epsg.format(source_crs), to_srs=epsg.format(srid))
        return Point(x, y)
Exemplo n.º 5
0
    def read(self, params, street_name, zip_code, street_number):
        """
        Queries an address using the federal GeoAdmin API location search.

        Args:
            params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request.
            street_name (unicode): The name of the street for the desired address.
            zip_code (int): The postal zipcode for the desired address.
            street_number (unicode): The house or so called street number of the desired address.
        """
        headers = {}
        if self._referer is not None:
            headers.update({'Referer': self._referer})
        request_params = {
            'type':
            self._type,
            'origins':
            self._origins,
            'searchText':
            u'{0} {1} {2}'.format(zip_code, street_name, street_number)
        }
        response = requests.get(self._geoadmin_url,
                                params=request_params,
                                proxies=self._proxies,
                                headers=headers)
        if response.status_code == requests.codes.ok:
            rp = Reprojector()
            srid = Config.get('srid')
            self.records = list()
            data = response.json()
            if 'results' in data:
                for item in data.get('results'):
                    attrs = item.get('attrs')
                    if isinstance(attrs,
                                  dict) and attrs.get('origin') == 'address':
                        x, y = rp.transform(
                            (attrs.get('lon'), attrs.get('lat')), to_srs=srid)
                        self.records.append(
                            AddressRecord(street_name=street_name,
                                          zip_code=zip_code,
                                          street_number=street_number,
                                          geom=Point(x, y)))
        else:
            response.raise_for_status()
Exemplo n.º 6
0
import json
from pyreproj import Reprojector

# defining projection
rp = Reprojector()
transform = rp.get_transformation_function(from_srs='epsg:25833', to_srs=4326)

# defining output files
coords = open("coords.json", "a")
districts = open("districts.json", "a")

# loading EPSG25833 data
INPUT_FILE = './ortsteil.json'
ortsfile = open(INPUT_FILE)
ortsdata = json.load(ortsfile)

# Example of JSON access
# mitte_name = ortsdata['FeatureCollection']['featureMember'][0]['re_ortsteil']['spatial_alias']['__text']
# mitte_loc = ortsdata['FeatureCollection']['featureMember'][0]['re_ortsteil']['spatial_geometry']['Polygon']['exterior']['LinearRing']['posList']['__text']

# Example projection
# mitte_loc_lst = mitte_loc.split()
# mitte_loc_pairs = [mitte_loc_lst[i:i+2] for i in range(0,len(mitte_loc_lst),2)]
# for i in mitte_loc_pairs:
#    lat_lng = transform(i[0], i[1])
#    print("{ lat: " + str(lat_lng[0]) + ", lng: " + str(lat_lng[1]) + " },")

for ortsteil in ortsdata['FeatureCollection']['featureMember']:
    name = ortsteil['re_ortsteil']['spatial_alias']['__text']
    districts.write(name + ",\n")
    coords.write("// " + name + "\n")
Exemplo n.º 7
0
 def __init__(self, crsEpsg):
     self.crsEpsg = crsEpsg
     rp = Reprojector()
     self.transform_fce = rp.get_transformation_function(to_srs=crsEpsg)