Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Empty LineString created with HasZ() is true #993

@ddowling

Description

@ddowling

I am trying to track down an issue in recent versions of GeoDjango where empty LineString objects are being created with the hasz property True. The following code is outputting True with libgeos version 3.12.0_CAPI_1.18.0. When run with 3.11.2-CAPI-1.17.2 the code putputs False

from django.contrib.gis.geos import LineString, geos_version
print(geos_version())
ls = LineString()
print(ls.hasz)

I have traced this down to the C libgeos API where GEOSGeom_createLineString is getting called with a NULL argument.
Following is a short C program that demonstrates this. When run with version 3.12.0 of libgeos it outputs GEOSHasZ() = 1. With version 3.11.0 it outputs GEOSHasZ() = 0.

#include <stdio.h>
#include <stdarg.h>

#include <geos_c.h>

static void geos_msg_handler(const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    vprintf (fmt, ap);
    va_end(ap);
}

int main()
{
    /* Send notice and error messages to the terminal */
    initGEOS(geos_msg_handler, geos_msg_handler);

    printf("GEOS Version %s\n", GEOSversion());

    GEOSGeometry* geom = GEOSGeom_createLineString(NULL);

    GEOSWKTWriter* writer = GEOSWKTWriter_create();
    char* wkt = GEOSWKTWriter_write(writer, geom);
    printf("Geometry: %s\n", wkt);
    printf("GEOSHasZ() = %d\n", GEOSHasZ(geom));

    /* Clean up allocated objects */
    GEOSWKTWriter_destroy( writer);
    GEOSGeom_destroy(geom);

    /* Clean up the global context */
    finishGEOS();

    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions