예제 #1
0
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;
	}

}
예제 #2
0
GEOSGeom msudf_getGeometry(unsigned char *buf,unsigned int length)
{
	int srid;
	GEOSGeom geom;

	geom = GEOSGeomFromWKB_buf(buf + 4,length - 4);
	if (geom != NULL) {
		srid = msudf_getInt(buf);
		GEOSSetSRID(geom,srid);
	}
	return geom;
}
        void test_wkb(std::string const& wkbhex, std::string const& wkt)
        {
            wkb_hex_decoder::binary_type wkb;
            wkb_hex_decoder::decode(wkbhex, wkb);

            geom1_ = GEOSGeomFromWKB_buf(&wkb[0], wkb.size());
            ensure("GEOSGeomFromWKB_buf failed to create geometry", nullptr != geom1_ );

            // TODO: Update test to compare with WKT-based geometry
            (void)wkt;
            //       ATM, some XYZ and XYZM geometries fail
            //geom2_ = GEOSWKTReader_read(reader_, wkt.c_str());
            //ensure ( 0 != geom2_ );
            //char result = GEOSEquals(geom1_, geom2_);
            //ensure_equals(result, char(1));
        }
예제 #4
0
파일: extractGridData.c 프로젝트: metno/wdb
struct GridPointDataListIterator * getExtractGridDataReturnValues(FunctionCallInfo fcinfo)
{
    struct PlaceSpecification ps;
    Datum placeSpec = PG_GETARG_DATUM(0);
    extractPlaceSpecification( & ps, & placeSpec );

    GEOSGeom location = NULL;
    if ( ! PG_ARGISNULL(1) )
    {
		bytea * locationRaw = PG_GETARG_BYTEA_P(1);
		location = GEOSGeomFromWKB_buf((unsigned char *) VARDATA(locationRaw), VARSIZE(locationRaw) - VARHDRSZ);
    }

    enum InterpolationType interpolation = (enum InterpolationType) PG_GETARG_INT32(2);
    FileId dataId = PG_GETARG_INT64(3);

    TransactionId xid = GetTopTransactionId();
    CommandId cid = GetCurrentCommandId(true); // Incremented for each function call in the same transaction

    // function takes ownership of location parameter
    struct GridPointDataListIterator * ret = readPoints(& ps, location, interpolation, dataId, xid, cid);
    return ret;
}
예제 #5
0
GEOSGeometry *_geo_from_wkb(const unsigned char *wkb,size_t size)
{
	return GEOSGeomFromWKB_buf(wkb,size);
}