makinacorpus / django-geojson

django-geojson is a collection of helpers to (de)serialize (Geo)Django objects into GeoJSON.
GNU Lesser General Public License v3.0
259 stars 69 forks source link

Make 'name' the default for 'crs_type' #117

Open henri-hulski opened 2 years ago

henri-hulski commented 2 years ago

Despite the docs link is still the default for the crs_type option.

You need to fix def get_crs(self):

    def get_crs(self):
        crs = {}
        crs_type = self.options.pop('crs_type', None)
        properties = {}
        if crs_type == "name":
            # todo: GeoJSON Spec: OGC CRS URNs such as "urn:ogc:def:crs:OGC:1.3:CRS84" shall be preferred over legacy identifiers such as "EPSG:4326":
            properties["name"] = "EPSG:%s" % (str(self.srid))
        else:  # preserve default behaviour
            crs_type = "link"
            properties["href"] = "http://spatialreference.org/ref/epsg/%s/" % (str(self.srid))
            properties["type"] = "proj4"
        crs["type"] = crs_type
        crs["properties"] = properties
        return crs
henri-hulski commented 2 years ago

BTW are you planning to implement the todo from the above code?

Gagaro commented 2 years ago

The documentation is pointing to the view: https://github.com/makinacorpus/django-geojson/blob/master/djgeojson/views.py#L60

Did you have an issue with the default value in the serializer?

BTW are you planning to implement the todo from the above code?

This is a very old TODO and I'm not sure of the consequences. Feel free to open a PR if you have a better idea about what is needed here.

henri-hulski commented 2 years ago

I'm using just the serializer for a geojson response. And when I don't set crs["type"] it uses link. Beside that the serializer works great. Especially the field mapping is for me the main advantage to the native Django GeoJSON serializer.