Skip to main content

Serializer

Convert a queryset to GeoJSON, http://geojson.org/

Attributes

AttributeTypeDescription
geometry_fieldstring = nullName of the model field that contains the geometry data to be used as the primary GeoJSON geometry.
id_fieldstring = nullName of the model field to be used as the 'id' member of the GeoJSON Feature object.
sridinteger = 4326The spatial reference identifier (SRID) used to transform geometries during serialization, defaulting to WGS84.
_ctsdict = nullA dictionary cache of CoordTransform objects keyed by source SRID to optimize repeated coordinate transformations.
_geometryobject = nullTemporary storage for the geometry object of the current model instance being processed during serialization.

Methods


start_serialization()

@classmethod
def start_serialization()

Initializes the output stream with the GeoJSON FeatureCollection header and prepares the coordinate transformation cache.


end_serialization()

@classmethod
def end_serialization()

Closes the GeoJSON FeatureCollection structure by writing the final closing brackets to the output stream.


start_object()

@classmethod
def start_object(
obj: [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model)
)

Prepares a single model instance for serialization and automatically identifies the geometry field if one was not explicitly provided.

Parameters

NameTypeDescription
obj[Model](../../../../db/models/base/model.md?sid=django_db_models_base_model)The Django model instance currently being processed for serialization.

get_dump_object()

@classmethod
def get_dump_object(
obj: [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model)
) - > dict

Constructs a dictionary representing a GeoJSON Feature, including its ID, properties, and transformed geometry data.

Parameters

NameTypeDescription
obj[Model](../../../../db/models/base/model.md?sid=django_db_models_base_model)The model instance whose data is being compiled into the Feature dictionary.

Returns

TypeDescription
dictA dictionary structured according to the GeoJSON Feature specification, ready for JSON encoding.

handle_field()

@classmethod
def handle_field(
obj: [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model),
field: [Field](../../../../forms/fields/field.md?sid=django_forms_fields_field)
)

Processes an individual model field, capturing geometry data if the field matches the designated geometry field name.

Parameters

NameTypeDescription
obj[Model](../../../../db/models/base/model.md?sid=django_db_models_base_model)The model instance containing the field being processed.
field[Field](../../../../forms/fields/field.md?sid=django_forms_fields_field)The specific model field instance to be evaluated or serialized.