Beispiel #1
0
    def _check_schema_driver_support(self):
        """Check support for the schema against the driver

        See GH#572 for discussion.
        """
        gdal_version_major = get_gdal_version_tuple().major

        for field in self._schema["properties"].values():
            field_type = field.split(":")[0]

            if not _driver_supports_field(self.driver, field_type):
                if self.driver == 'GPKG' and gdal_version_major < 2 and field_type == "datetime":
                    raise DriverSupportError(
                        "GDAL 1.x GPKG driver does not support datetime fields"
                    )
                else:
                    raise DriverSupportError(
                        "{driver} does not support {field_type} "
                        "fields".format(driver=self.driver,
                                        field_type=field_type))
            elif field_type in {
                    'time', 'datetime', 'date'
            } and _driver_converts_field_type_silently_to_str(
                    self.driver, field_type):
                if self._driver == "GeoJSON" and gdal_version_major < 2 and field_type in {
                        'datetime', 'date'
                }:
                    warnings.warn(
                        "GeoJSON driver in GDAL 1.x silently converts {} to string"
                        " in non-standard format".format(field_type))
                else:
                    warnings.warn(
                        "{driver} driver silently converts {field_type} "
                        "to string".format(driver=self.driver,
                                           field_type=field_type))
    def _check_schema_driver_support(self):
        """Check support for the schema against the driver

        See GH#572 for discussion.
        """
        gdal_version_major = get_gdal_version_tuple().major

        for field in self._schema["properties"].values():
            field_type = field.split(":")[0]
            if self._driver == "ESRI Shapefile":
                if field_type == "datetime":
                    raise DriverSupportError(
                        "ESRI Shapefile does not support datetime fields")
                elif field_type == "time":
                    raise DriverSupportError(
                        "ESRI Shapefile does not support time fields")
            elif self._driver == "GPKG":
                if field_type == "time":
                    raise DriverSupportError(
                        "GPKG does not support time fields")
                elif gdal_version_major == 1:
                    if field_type == "datetime":
                        raise DriverSupportError(
                            "GDAL 1.x GPKG driver does not support datetime fields"
                        )
            elif self._driver == "GeoJSON":
                if gdal_version_major == 1:
                    if field_type == "date":
                        warnings.warn(
                            "GeoJSON driver in GDAL 1.x silently converts date to string in non-standard format"
                        )
                    elif field_type == "datetime":
                        warnings.warn(
                            "GeoJSON driver in GDAL 1.x silently converts datetime to string in non-standard format"
                        )
                    elif field_type == "time":
                        warnings.warn(
                            "GeoJSON driver in GDAL 1.x silently converts time to string"
                        )