Esempio n. 1
0
File: io.py Progetto: 8H33W00/piro13
class WKBReader_st(Structure):
    pass


class WKBWriter_st(Structure):
    pass


WKT_READ_PTR = POINTER(WKTReader_st)
WKT_WRITE_PTR = POINTER(WKTWriter_st)
WKB_READ_PTR = POINTER(WKBReader_st)
WKB_WRITE_PTR = POINTER(WKBReader_st)

# WKTReader routines
wkt_reader_create = GEOSFuncFactory('GEOSWKTReader_create',
                                    restype=WKT_READ_PTR)
wkt_reader_destroy = GEOSFuncFactory('GEOSWKTReader_destroy',
                                     argtypes=[WKT_READ_PTR])

wkt_reader_read = GEOSFuncFactory('GEOSWKTReader_read',
                                  argtypes=[WKT_READ_PTR, c_char_p],
                                  restype=GEOM_PTR,
                                  errcheck=check_geom)
# WKTWriter routines
wkt_writer_create = GEOSFuncFactory('GEOSWKTWriter_create',
                                    restype=WKT_WRITE_PTR)
wkt_writer_destroy = GEOSFuncFactory('GEOSWKTWriter_destroy',
                                     argtypes=[WKT_WRITE_PTR])

wkt_writer_write = GEOSFuncFactory('GEOSWKTWriter_write',
                                   argtypes=[WKT_WRITE_PTR, GEOM_PTR],
Esempio n. 2
0
from django.utils.six.moves import range

__all__ = ['geos_area', 'geos_distance', 'geos_length', 'geos_isvalidreason']


class DblFromGeom(GEOSFuncFactory):
    """
    Argument is a Geometry, return type is double that is passed
    in by reference as the last argument.
    """
    restype = c_int  # Status code returned
    errcheck = staticmethod(check_dbl)

    def get_func(self, num_geom=1):
        argtypes = [GEOM_PTR for i in range(num_geom)]
        argtypes += [POINTER(c_double)]
        self.argtypes = argtypes
        return super(DblFromGeom, self).get_func()


# ### ctypes prototypes ###

# Area, distance, and length prototypes.
geos_area = DblFromGeom('GEOSArea')
geos_distance = DblFromGeom('GEOSDistance', num_geom=2)
geos_length = DblFromGeom('GEOSLength')
geos_isvalidreason = GEOSFuncFactory('GEOSisValidReason',
                                     restype=geos_char_p,
                                     errcheck=check_string,
                                     argtypes=[GEOM_PTR])
Esempio n. 3
0
# Deprecated creation routines from WKB, HEX, WKT
from_hex = BinConstructor('GEOSGeomFromHEX_buf')
from_wkb = BinConstructor('GEOSGeomFromWKB_buf')
from_wkt = GeomOutput('GEOSGeomFromWKT', [c_char_p])

# Deprecated output routines
to_hex = BinOutput('GEOSGeomToHEX_buf')
to_wkb = BinOutput('GEOSGeomToWKB_buf')
to_wkt = StringFromGeom('GEOSGeomToWKT')

# The GEOS geometry type, typeid, num_coordinates and number of geometries
geos_normalize = IntFromGeom('GEOSNormalize')
geos_type = StringFromGeom('GEOSGeomType')
geos_typeid = IntFromGeom('GEOSGeomTypeId')
get_dims = GEOSFuncFactory('GEOSGeom_getDimensions',
                           argtypes=[GEOM_PTR],
                           restype=c_int)
get_num_coords = IntFromGeom('GEOSGetNumCoordinates')
get_num_geoms = IntFromGeom('GEOSGetNumGeometries')

# Geometry creation factories
create_point = GeomOutput('GEOSGeom_createPoint', [CS_PTR])
create_linestring = GeomOutput('GEOSGeom_createLineString', [CS_PTR])
create_linearring = GeomOutput('GEOSGeom_createLinearRing', [CS_PTR])

# Polygon and collection creation routines are special and will not
# have their argument types defined.
create_polygon = GeomOutput('GEOSGeom_createPolygon', None)
create_empty_polygon = GeomOutput('GEOSGeom_createEmptyPolygon', None)
create_collection = GeomOutput('GEOSGeom_createCollection', None)
Esempio n. 4
0
# ## Coordinate Sequence ctypes prototypes ##

# Coordinate Sequence constructors & cloning.
cs_clone = CsOutput("GEOSCoordSeq_clone", argtypes=[CS_PTR])
create_cs = CsOutput("GEOSCoordSeq_create", argtypes=[c_uint, c_uint])
get_cs = CsOutput("GEOSGeom_getCoordSeq", argtypes=[GEOM_PTR])

# Getting, setting ordinate
cs_getordinate = CsOperation("GEOSCoordSeq_getOrdinate",
                             ordinate=True,
                             get=True)
cs_setordinate = CsOperation("GEOSCoordSeq_setOrdinate", ordinate=True)

# For getting, x, y, z
cs_getx = CsOperation("GEOSCoordSeq_getX", get=True)
cs_gety = CsOperation("GEOSCoordSeq_getY", get=True)
cs_getz = CsOperation("GEOSCoordSeq_getZ", get=True)

# For setting, x, y, z
cs_setx = CsOperation("GEOSCoordSeq_setX")
cs_sety = CsOperation("GEOSCoordSeq_setY")
cs_setz = CsOperation("GEOSCoordSeq_setZ")

# These routines return size & dimensions.
cs_getsize = CsInt("GEOSCoordSeq_getSize")
cs_getdims = CsInt("GEOSCoordSeq_getDimensions")

cs_is_ccw = GEOSFuncFactory("GEOSCoordSeq_isCCW",
                            restype=c_int,
                            argtypes=[CS_PTR, POINTER(c_byte)])
Esempio n. 5
0
"""
 Error checking functions for GEOS ctypes prototype functions.
"""
from ctypes import c_void_p, string_at

from django.contrib.gis.geos.error import GEOSException
from django.contrib.gis.geos.libgeos import GEOSFuncFactory

# Getting the `free` routine used to free the memory allocated for
# string pointers returned by GEOS.
free = GEOSFuncFactory('GEOSFree')
free.argtypes = [c_void_p]


def last_arg_byref(args):
    "Returns the last C argument's value by reference."
    return args[-1]._obj.value


def check_dbl(result, func, cargs):
    "Checks the status code and returns the double value passed in by reference."
    # Checking the status code
    if result != 1:
        return None
    # Double passed in by reference, return its value.
    return last_arg_byref(cargs)


def check_geom(result, func, cargs):
    "Error checking on routines that return Geometries."
    if not result:
Esempio n. 6
0
"""
 Error checking functions for GEOS ctypes prototype functions.
"""
from ctypes import c_void_p, string_at

from django.contrib.gis.geos.error import GEOSException
from django.contrib.gis.geos.libgeos import GEOSFuncFactory

# Getting the `free` routine used to free the memory allocated for
# string pointers returned by GEOS.
free = GEOSFuncFactory("GEOSFree")
free.argtypes = [c_void_p]


def last_arg_byref(args):
    "Return the last C argument's value by reference."
    return args[-1]._obj.value


def check_dbl(result, func, cargs):
    "Check the status code and returns the double value passed in by reference."
    # Checking the status code
    if result != 1:
        return None
    # Double passed in by reference, return its value.
    return last_arg_byref(cargs)


def check_geom(result, func, cargs):
    "Error checking on routines that return Geometries."
    if not result:
Esempio n. 7
0
class WKBReader_st(Structure):
    pass


class WKBWriter_st(Structure):
    pass


WKT_READ_PTR = POINTER(WKTReader_st)
WKT_WRITE_PTR = POINTER(WKTWriter_st)
WKB_READ_PTR = POINTER(WKBReader_st)
WKB_WRITE_PTR = POINTER(WKBReader_st)

# WKTReader routines
wkt_reader_create = GEOSFuncFactory('GEOSWKTReader_create',
                                    restype=WKT_READ_PTR)
wkt_reader_destroy = GEOSFuncFactory('GEOSWKTReader_destroy',
                                     argtypes=[WKT_READ_PTR])

wkt_reader_read = GEOSFuncFactory('GEOSWKTReader_read',
                                  argtypes=[WKT_READ_PTR, c_char_p],
                                  restype=GEOM_PTR,
                                  errcheck=check_geom)
# WKTWriter routines
wkt_writer_create = GEOSFuncFactory('GEOSWKTWriter_create',
                                    restype=WKT_WRITE_PTR)
wkt_writer_destroy = GEOSFuncFactory('GEOSWKTWriter_destroy',
                                     argtypes=[WKT_WRITE_PTR])

wkt_writer_write = GEOSFuncFactory('GEOSWKTWriter_write',
                                   argtypes=[WKT_WRITE_PTR, GEOM_PTR],
Esempio n. 8
0
from ctypes import c_char

from django.contrib.gis.geos.libgeos import (
    GEOM_PTR,
    PREPGEOM_PTR,
    GEOSFuncFactory,
)
from django.contrib.gis.geos.prototypes.errcheck import check_predicate

# Prepared geometry constructor and destructors.
geos_prepare = GEOSFuncFactory('GEOSPrepare',
                               argtypes=[GEOM_PTR],
                               restype=PREPGEOM_PTR)
prepared_destroy = GEOSFuncFactory('GEOSPreparedGeom_destroy',
                                   argtpes=[PREPGEOM_PTR])


# Prepared geometry binary predicate support.
class PreparedPredicate(GEOSFuncFactory):
    argtypes = [PREPGEOM_PTR, GEOM_PTR]
    restype = c_char
    errcheck = staticmethod(check_predicate)


prepared_contains = PreparedPredicate('GEOSPreparedContains')
prepared_contains_properly = PreparedPredicate('GEOSPreparedContainsProperly')
prepared_covers = PreparedPredicate('GEOSPreparedCovers')
prepared_intersects = PreparedPredicate('GEOSPreparedIntersects')

# Functions added in GEOS 3.3
prepared_crosses = PreparedPredicate('GEOSPreparedCrosses')
Esempio n. 9
0
geos_centroid = Topology('GEOSGetCentroid')
geos_convexhull = Topology('GEOSConvexHull')
geos_difference = Topology('GEOSDifference', argtypes=[GEOM_PTR, GEOM_PTR])
geos_envelope = Topology('GEOSEnvelope')
geos_intersection = Topology('GEOSIntersection', argtypes=[GEOM_PTR, GEOM_PTR])
geos_linemerge = Topology('GEOSLineMerge')
geos_pointonsurface = Topology('GEOSPointOnSurface')
geos_preservesimplify = Topology('GEOSTopologyPreserveSimplify',
                                 argtypes=[GEOM_PTR, c_double])
geos_simplify = Topology('GEOSSimplify', argtypes=[GEOM_PTR, c_double])
geos_symdifference = Topology('GEOSSymDifference',
                              argtypes=[GEOM_PTR, GEOM_PTR])
geos_union = Topology('GEOSUnion', argtypes=[GEOM_PTR, GEOM_PTR])

geos_cascaded_union = GEOSFuncFactory('GEOSUnionCascaded',
                                      argtypes=[GEOM_PTR],
                                      restype=GEOM_PTR)
geos_unary_union = GEOSFuncFactory('GEOSUnaryUnion',
                                   argtypes=[GEOM_PTR],
                                   restype=GEOM_PTR)

# GEOSRelate returns a string, not a geometry.
geos_relate = GEOSFuncFactory('GEOSRelate',
                              argtypes=[GEOM_PTR, GEOM_PTR],
                              restype=geos_char_p,
                              errcheck=check_string)

# Linear referencing routines
geos_project = GEOSFuncFactory('GEOSProject',
                               argtypes=[GEOM_PTR, GEOM_PTR],
                               restype=c_double,
Esempio n. 10
0
"""
 Error checking functions for GEOS ctypes prototype functions.
"""
from ctypes import c_void_p, string_at

from django.contrib.gis.geos.error import GEOSException
from django.contrib.gis.geos.libgeos import GEOSFuncFactory

# Getting the `free` routine used to free the memory allocated for
# string pointers returned by GEOS.
free = GEOSFuncFactory('GEOSFree')
free.argtypes = [c_void_p]


def last_arg_byref(args):
<<<<<<< HEAD
    "Returns the last C argument's value by reference."
=======
    "Return the last C argument's value by reference."
>>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435
    return args[-1]._obj.value


def check_dbl(result, func, cargs):
<<<<<<< HEAD
    "Checks the status code and returns the double value passed in by reference."
=======
    "Check the status code and returns the double value passed in by reference."
>>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435
    # Checking the status code
    if result != 1:
Esempio n. 11
0
geos_centroid = Topology("GEOSGetCentroid")
geos_convexhull = Topology("GEOSConvexHull")
geos_difference = Topology("GEOSDifference", argtypes=[GEOM_PTR, GEOM_PTR])
geos_envelope = Topology("GEOSEnvelope")
geos_intersection = Topology("GEOSIntersection", argtypes=[GEOM_PTR, GEOM_PTR])
geos_linemerge = Topology("GEOSLineMerge")
geos_pointonsurface = Topology("GEOSPointOnSurface")
geos_preservesimplify = Topology(
    "GEOSTopologyPreserveSimplify", argtypes=[GEOM_PTR, c_double]
)
geos_simplify = Topology("GEOSSimplify", argtypes=[GEOM_PTR, c_double])
geos_symdifference = Topology("GEOSSymDifference", argtypes=[GEOM_PTR, GEOM_PTR])
geos_union = Topology("GEOSUnion", argtypes=[GEOM_PTR, GEOM_PTR])

geos_unary_union = GEOSFuncFactory(
    "GEOSUnaryUnion", argtypes=[GEOM_PTR], restype=GEOM_PTR
)

# GEOSRelate returns a string, not a geometry.
geos_relate = GEOSFuncFactory(
    "GEOSRelate",
    argtypes=[GEOM_PTR, GEOM_PTR],
    restype=geos_char_p,
    errcheck=check_string,
)

# Linear referencing routines
geos_project = GEOSFuncFactory(
    "GEOSProject",
    argtypes=[GEOM_PTR, GEOM_PTR],
    restype=c_double,
Esempio n. 12
0
"""
 Error checking functions for GEOS ctypes prototype functions.
"""
from ctypes import c_void_p, string_at
from django.contrib.gis.geos.error import GEOSException
from django.contrib.gis.geos.libgeos import GEOSFuncFactory
# Getting the `free` routine used to free the memory allocated for
# string pointers returned by GEOS.
free = GEOSFuncFactory('GEOSFree')
free.argtypes = [c_void_p]

def last_arg_byref(args):
    "Returns the last C argument's value by reference."
    return args[-1]._obj.value

def check_dbl(result, func, cargs):
    "Checks the status code and returns the double value passed in by reference."
    # Checking the status code
    if result != 1:
        return None
    # Double passed in by reference, return its value.
    return last_arg_byref(cargs)

def check_geom(result, func, cargs):
    "Error checking on routines that return Geometries."
    if not result:
        raise GEOSException('Error encountered checking Geometry returned from GEOS C function "%s".' % func.__name__)
    return result

def check_minus_one(result, func, cargs):