def build_valid_vert_crs(crs: pyproj_VerticalCRS, regions: [str], datum_data: object) -> (pyproj_VerticalCRS, str, str): """ Add the regions and pipeline to the remarks section of the wkt for the provided pyproj VerticalCRS object. Parameters ---------- crs : pyproj.crs.VerticalCRS The vertical crs object to add the pipeline and region into. regions : [str] The regions to add into the crs remarks. vdatum_version_string version of vdatum, used in the geoid/region lookup Returns ------- result (pyproj.crs.VerticalCRS, str) First value is the vertical crs object with the remarks updated to add the region and pipeline. The second value is the vyperdatum.pipeline datum identifier. The third value is the pipeline string. """ datum = guess_vertical_datum_from_string(crs.name) pipeline = None new_crs = VerticalPipelineCRS(datum_data=datum_data) new_crs.from_wkt(crs.to_wkt()) if datum: for region in regions: if datum == 'ellipse': new_pipeline = '[]' else: geoid_name = datum_data.get_geoid_name(region) new_pipeline = get_regional_pipeline('ellipse', datum, region, geoid_name) if new_pipeline: new_crs.add_pipeline(new_pipeline, region) pipeline = new_crs.pipeline_string if datum == 'geoid': geoids = [ gd for gd in geoid_possibilities if pipeline.find(gd) != -1 ] if len(geoids) > 1: raise NotImplementedError( f'Found multiple geoids in the pipeline string, only one geoid per pipeline supported at this time: {geoids}' ) elif len(geoids) == 0: raise ValueError( f'No geoid found in given pipeline string: {pipeline}') newdatum = geoids[0] new_crs.datum_name = newdatum valid_vert_crs = CRS.from_wkt(new_crs.to_wkt()) else: valid_vert_crs = None return valid_vert_crs, datum, pipeline
def read_identifiers(layer: str) -> tuple[str, CRS, list[Any]]: """Read feature source geometries Parameters: layer: path to the feature data to read Returns: feature geometry type, feature source crs as well-known text (WKT), shapely geometries """ with fiona.open(layer) as feature_src: supported = ['Point', 'LineString', '3D Point', '3D LineString'] schema_geometry = feature_src.schema['geometry'] try: if schema_geometry not in supported: raise click.BadParameter('Geometry must be one of: {}'.format(supported)) except: raise click.BadParameter('Unable to obtain schema from {}'.format(layer)) idx = [feature['id'] for feature in feature_src] feature_crs = CRS.from_wkt(feature_src.crs_wkt) return schema_geometry, feature_crs, idx
def set_crs(self, new_crs: Union[str, int, tuple], regions: [str] = None): """ Set the object vertical and / or horizontal crs using either an epsg code or wkt. Regions are also optionally set with a list of VDatum region strings. Parameters ---------- new_crs : Union[str, int, tuple] A wkt string or a vyperdatum vertical datum definition string or an epsg code may be provided either on its own or as a tuple pair. While the order (horizontal or vertical) does not matter, if they contain information for the same frame (horizontal or vertical) the second will overwrite the first. Once the provided object datums are set, the object compound attribute is set if the horizontal, verical, and region information is available. regions : [str], optional A list of VDatum region strings. These values will overwrite the values contained in the vertical WKT if they exist. The default is None. Raises ------ ValueError If a tuple of length greater than two is provided or if the provided value(s) are not a string or an integer. Returns ------- None. """ # check the input type if type(new_crs) == tuple: if len(new_crs) > 2: len_crs = len(new_crs) raise ValueError( f'The provided crs {new_crs} is {len_crs} in length but should have a length of two.' ) else: new_crs = (new_crs, ) # create pyproj crs based on the input type for entry in new_crs: if type(entry) == str: crs_str = entry if entry.lower() in datum_definition: if entry == 'ellipse' and self._hori: entry = f'{self._hori.name}_ellipse' tmp_crs = VerticalPipelineCRS(datum_data=self.datum_data, vert_datum_name=entry) crs_str = tmp_crs.to_wkt() crs = CRS.from_wkt(crs_str) self._set_single(crs) elif type(entry) == int: crs = CRS.from_epsg(entry) self._set_single(crs) else: raise ValueError( f'The crs description type {entry} is not recognized.') if regions: self._regions = regions self._update_and_build_compound()
def to_compound_crs(self): return CRS.from_wkt(self.to_compound_wkt())
def to_crs(self): return CRS.from_wkt(self.to_wkt())
def from_wkt(string): """Returns a CRS from a WKT string specification""" return CRS.from_wkt(string)