~test_capigeosrelateboundarynoderule_data()
 {
     GEOSGeom_destroy(geom1_);
     GEOSGeom_destroy(geom2_);
     GEOSFree(pat_);
     finishGEOS();
 }
Handle<Value> Geometry::Relate(const Arguments& args)
{
    HandleScope scope;
    Geometry *geom = ObjectWrap::Unwrap<Geometry>(args.This());
    if (args.Length() < 1)
        return ThrowException(String::New("requires at least one argument"));
    Geometry *other = ObjectWrap::Unwrap<Geometry>(args[0]->ToObject());
    if (args.Length() == 1) {
        // Gets a relation pattern (string) from the two geometries
        char *pattern = GEOSRelate(geom->geos_geom_, other->geos_geom_);
        if (pattern == NULL)
            return ThrowException(String::New("couldn't get relate pattern"));
        Local<Value> pattern_obj = String::New(pattern);
        GEOSFree(pattern);
        return scope.Close(pattern_obj);
    } else if (args.Length() == 2) {
        // Returns a boolean if the two geometries relate according to the pattern argument
        String::Utf8Value pattern(args[1]->ToString());
        unsigned char r = GEOSRelatePattern(geom->geos_geom_, other->geos_geom_, *pattern);
        if (r == 2) {
            return ThrowException(String::New("relate by pattern failed"));
        }
        return r ? True() : False();
    }
    return ThrowException(String::New("invalid number of arguments"));
}
char *msudf_transform(UDF_INIT *initid, UDF_ARGS *args, char *buf,
	unsigned long *length, char *is_null, char *error)
{
	unsigned char *wkb = NULL;
	size_t wkbsize;
	GEOSGeom g1,g2 =NULL;
	
	msudf_params *params;
	int srid_src,srid_dst;


	params = (msudf_params *) initid->ptr;
	

	DEBUG("msudf_transform");
	wkb = (unsigned char *) (args->args[0]);
	g1 = GEOSGeomFromWKB_buf(wkb + 4,args->lengths[0] - 4);
	srid_src = msudf_getInt(wkb);
	wkb = NULL;

	DEBUG("srid_src: %d",srid_src);
	if ((params->pj_src == NULL) || (params->srid_src != srid_src)) {
		params->pj_src = pj_init_plus(args->args[1]);
		params->srid_src = srid_src;
	}

	srid_dst = msudf_getInt((unsigned char *) args->args[2]);
	DEBUG("srid_dst: %d",srid_dst);
	if ((params->pj_dst == NULL) || (params->srid_dst != srid_dst)) {
		params->pj_dst = pj_init_plus(args->args[3]);
		params->srid_dst = srid_dst;
	}

	if (params->pj_src != NULL && params->pj_dst != NULL && g1 != NULL) {
		g2 = gu_transformGeom(g1,params->pj_src,params->pj_dst);
		wkb = GEOSGeomToWKB_buf(g2,&wkbsize);
	} else {
		// initid->ptr = NULL;
		strcpy(error,"Invalid geometry.");
	}

	if (g1 != NULL) GEOSGeom_destroy(g1);
	if (g2 != NULL) GEOSGeom_destroy(g2);


	if (wkb != NULL) {
		*length = (long)wkbsize + 4;
		if (params->buf != NULL) free(params->buf);
		params->buf = (char *) malloc(*length);
		memcpy(params->buf,args->args[2],4);
		memcpy((char *)params->buf + 4,wkb,wkbsize);
		GEOSFree((char *)wkb);
		return params->buf;
	} else {
		*is_null = 1;
		return NULL;
	}

}
 ~test_capigeosminimumrectangle_data()
 {
     GEOSGeom_destroy(input_);
     input_ = nullptr;
     GEOSWKTWriter_destroy(wktw_);
     GEOSFree(wkt_);
     wkt_ = nullptr;
     finishGEOS();
 }
Exemple #5
0
void geo_bound(sqlite3_context *context,int argc,sqlite3_value **argv)
{
	if(argc >= 1)
	{
		const unsigned char* ogc;
		unsigned char* ret_geo_buf;
		size_t size;
		double x1,x2,y1,y2;
		GEOSCoordSequence* seq = 0;
		GEOSGeometry* geometry = 0;
		GEOSGeometry* middle_geo = 0;
		
		_init_geos();
		if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB)
		{
			size = sqlite3_value_bytes(argv[0]);
			ogc = (const unsigned char*)sqlite3_value_blob(argv[0]);
			middle_geo = _geo_from_wkb(ogc,size);
		}
		else if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_TEXT)
		{
			ogc = sqlite3_value_text(argv[0]);
			middle_geo = _geo_from_wkt(ogc);
		}
		else if(argc == 4)
		{
			x1 = sqlite3_value_double(argv[0]);
			y1 = sqlite3_value_double(argv[1]);
			x2 = sqlite3_value_double(argv[2]);
			y2 = sqlite3_value_double(argv[3]);

			seq = GEOSCoordSeq_create(2,2);
			GEOSCoordSeq_setX(seq,0,x1);
			GEOSCoordSeq_setY(seq,0,y1);
			GEOSCoordSeq_setX(seq,1,x2);
			GEOSCoordSeq_setY(seq,1,y2);

			middle_geo = GEOSGeom_createLineString(seq);
		}

		if(middle_geo != 0)
		{
			geometry = GEOSEnvelope(middle_geo);
			if(geometry != 0)
			{
				ret_geo_buf = GEOSGeomToWKB_buf(geometry,&size);
				sqlite3_result_blob(context,ret_geo_buf,size,SQLITE_TRANSIENT);
				GEOSGeom_destroy(geometry);
				GEOSFree(ret_geo_buf);
			}
			GEOSGeom_destroy(middle_geo);
		}

		finishGEOS();
	}
}
Exemple #6
0
void msGEOSFreeWKT(char* pszGEOSWKT)
{
#ifdef USE_GEOS
#if GEOS_VERSION_MAJOR > 3 || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 2)
  GEOSFree(pszGEOSWKT);
#endif
#else
  msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSFreeWKT()");
#endif
}
 ~test_capioffsetcurve_data()
 {
     GEOSGeom_destroy(geom1_);
     GEOSGeom_destroy(geom2_);
     GEOSWKTWriter_destroy(wktw_);
     GEOSFree(wkt_);
     geom1_ = 0;
     geom2_ = 0;
     wkt_ = 0;
     finishGEOS();
 }
Handle<Value> Geometry::GetType(Local<String> name, const AccessorInfo& info)
{
    HandleScope scope;
    Geometry *geom = ObjectWrap::Unwrap<Geometry>(info.Holder());
    char *type = GEOSGeomType(geom->geos_geom_);
    if (type == NULL)
        return ThrowException(String::New("couldn't get geometry type"));
    Handle<Value> type_obj = String::New(type);
    GEOSFree(type);
    return scope.Close(type_obj);
}
Handle<Value> Geometry::ToWKT(const Arguments& args)
{
    Local<Value> wktjs;
    GEOSWKTWriter *wkt_writer = GEOSWKTWriter_create();
    Geometry *geom = ObjectWrap::Unwrap<Geometry>(args.This());
    HandleScope scope;
    if (geom->geos_geom_ != NULL) {
        char *wkt = GEOSWKTWriter_write(wkt_writer, geom->geos_geom_);
        wktjs = String::New(wkt);
        GEOSFree(wkt);
    } else {
        wktjs = String::New("");
    }
    return scope.Close(wktjs);
}
char *msudf_returnGeometry(UDF_INIT *initid,unsigned long* length,GEOSGeom geom)
{
	unsigned char *wkb;
	msudf_params *params;
	size_t wkbsize;
	int srid;

	wkb = GEOSGeomToWKB_buf(geom,&wkbsize);
	*length = (long)wkbsize + 4;
	srid = GEOSGetSRID(geom);

	params = (msudf_params *) initid->ptr;
	if (params->buf != NULL) free(params->buf);
	params->buf = (char *) malloc(*length);

	memcpy(params->buf,&srid,4);
	memcpy((char *)params->buf + 4,wkb,wkbsize);
	GEOSFree((char *)wkb);
	return params->buf;
}
Exemple #11
0
void geo_type(sqlite3_context *context,int argc,sqlite3_value **argv)
{
	if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB)
	{ 
		GEOSGeometry* geometry;
		char* type;
		const void* data = sqlite3_value_blob(argv[0]);
		size_t data_size = sqlite3_value_bytes(argv[0]);

		_init_geos();
		geometry = _geo_from_wkb((const unsigned char*)data,data_size);
		if(geometry != 0)
		{
			type = GEOSGeomType(geometry);
			sqlite3_result_text(context,type,-1,SQLITE_TRANSIENT);

			GEOSFree(type);
		}
		GEOSGeom_destroy(geometry);
		finishGEOS();
	}
}
Exemple #12
0
void geo_wkb(sqlite3_context *context,int argc,sqlite3_value **argv)
{
	if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_TEXT)
	{ 
		GEOSGeometry* geometry;
		const char* wkt = (const char*)sqlite3_value_text(argv[0]);
		unsigned char* wkb;
		size_t size;

		_init_geos();
		geometry = _geo_from_wkt(wkt);
		if(geometry != 0)
		{
			wkb = GEOSGeomToWKB_buf(geometry,&size);
			sqlite3_result_blob(context,(const void*)wkb,size,SQLITE_TRANSIENT);

			GEOSFree(wkb);
		}
		GEOSGeom_destroy(geometry);
		finishGEOS();
	}
}