<s> from ctypes import c_double , c_int , c_uint , POINTER <EOL> from django . contrib . gis . geos . libgeos import lgeos , GEOM_PTR , CS_PTR <EOL> from django . contrib . gis . geos . prototypes . errcheck import last_arg_byref , GEOSException <EOL> def check_cs_ptr ( result , func , cargs ) : <EOL> "<STR_LIT>" <EOL> if not result : <EOL> raise GEOSException ( '<STR_LIT>' % func . __name__ ) <EOL> return result <EOL> def check_cs_op ( result , func , cargs ) : <EOL> "<STR_LIT>" <EOL> if result == <NUM_LIT:0> : <EOL> raise GEOSException ( '<STR_LIT>' ) <EOL> else : <EOL> return result <EOL> def check_cs_get ( result , func , cargs ) : <EOL> "<STR_LIT>" <EOL> check_cs_op ( result , func , cargs ) <EOL> return last_arg_byref ( cargs ) <EOL> def cs_int ( func ) : <EOL> "<STR_LIT>" <EOL> func . argtypes = [ CS_PTR , POINTER ( c_uint ) ] <EOL> func . restype = c_int <EOL> func . errcheck = check_cs_get <EOL> return func <EOL> def cs_operation ( func , ordinate = False , get = False ) : <EOL> "<STR_LIT>" <EOL> if get : <EOL> func . errcheck = check_cs_get <EOL> dbl_param = POINTER ( c_double ) <EOL> else : <EOL> func . errcheck = check_cs_op <EOL> dbl_param = c_double <EOL> if ordinate : <EOL> func . argtypes = [ CS_PTR , c_uint , c_uint , dbl_param ] <EOL> else : <EOL> func . argtypes = [ CS_PTR , c_uint , dbl_param ] <EOL> func . restype = c_int <EOL> return func <EOL> def cs_output ( func , argtypes ) : <EOL> "<STR_LIT>" <EOL> func . argtypes = argtypes <EOL> func . restype = CS_PTR <EOL> func . errcheck = check_cs_ptr <EOL> return func <EOL> cs_clone = cs_output ( lgeos . GEOSCoordSeq_clone , [ CS_PTR ] ) <EOL> create_cs = cs_output ( lgeos . GEOSCoordSeq_create , [ c_uint , c_uint ] ) <EOL> get_cs = cs_output ( lgeos . GEOSGeom_getCoordSeq , [ GEOM_PTR ] ) <EOL> cs_getordinate = cs_operation ( lgeos . GEOSCoordSeq_getOrdinate , ordinate = True , get = True ) <EOL> cs_setordinate = cs_operation ( lgeos . GEOSCoordSeq_setOrdinate , ordinate = True ) <EOL> cs_getx = cs_operation ( lgeos . GEOSCoordSeq_getX , get = True ) <EOL> cs_gety = cs_operation ( lgeos . GEOSCoordSeq_getY , get = True ) <EOL> cs_getz = cs_operation ( lgeos . GEOSCoordSeq_getZ , get = True ) <EOL> cs_setx = cs_operation ( lgeos . GEOSCoordSeq_setX ) <EOL> cs_sety = cs_operation ( lgeos . GEOSCoordSeq_setY ) <EOL> cs_setz = cs_operation ( lgeos . GEOSCoordSeq_setZ ) <EOL> cs_getsize = cs_int ( lgeos . GEOSCoordSeq_getSize ) <EOL> cs_getdims = cs_int ( lgeos . GEOSCoordSeq_getDimensions ) </s>
