From 57664ef7799bbc03e6208837ec6d5ba555be5e9b Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 20 Aug 2004 16:35:38 +0000 Subject: [PATCH] initial skel for transform() git-svn-id: http://svn.osgeo.org/postgis/trunk@714 b70326c6-7e19-0410-871a-916f4a2858ee --- lwgeom/lwgeom_transform.c | 275 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 275 insertions(+) diff --git a/lwgeom/lwgeom_transform.c b/lwgeom/lwgeom_transform.c index e69de29bb..f92f2669d 100644 --- a/lwgeom/lwgeom_transform.c +++ b/lwgeom/lwgeom_transform.c @@ -0,0 +1,275 @@ + +#include +#include +#include +#include +#include + +#include "postgres.h" +#include "fmgr.h" + +#include "lwgeom.h" + +// if USE_PROJECTION undefined, we get a do-nothing transform() function +#ifndef USE_PROJ + +PG_FUNCTION_INFO_V1(transform_geom); +Datum transform_geom(PG_FUNCTION_ARGS) +{ + + elog(ERROR,"PostGIS transform() called, but support not compiled in. Modify your makefile to add proj support, remake and re-install"); + PG_RETURN_NULL(); +} + +PG_FUNCTION_INFO_V1(postgis_proj_version); +Datum postgis_proj_version(PG_FUNCTION_ARGS) +{ + PG_RETURN_NULL(); +} + +#else // defined USE_PROJ + +#include "projects.h" + +PJ *make_project(char *str1); +void to_rad(POINT3D *pts, int num_points); +void to_dec(POINT3D *pts, int num_points); +int pj_transform_nodatum(PJ *srcdefn, PJ *dstdefn, long point_count, int point_offset, double *x, double *y, double *z ); + +//this is *exactly* the same as PROJ.4's pj_transform(), but it doesnt do the +// datum shift. +int +pj_transform_nodatum(PJ *srcdefn, PJ *dstdefn, long point_count, +int point_offset, double *x, double *y, double *z ) +{ + long i; + //int need_datum_shift; + + pj_errno = 0; + + if( point_offset == 0 ) + point_offset = 1; + + if( !srcdefn->is_latlong ) + { + for( i = 0; i < point_count; i++ ) + { + XY projected_loc; + LP geodetic_loc; + + projected_loc.u = x[point_offset*i]; + projected_loc.v = y[point_offset*i]; + + geodetic_loc = pj_inv( projected_loc, srcdefn ); + if( pj_errno != 0 ) + return pj_errno; + + x[point_offset*i] = geodetic_loc.u; + y[point_offset*i] = geodetic_loc.v; + } + } + + if( !dstdefn->is_latlong ) + { + for( i = 0; i < point_count; i++ ) + { + XY projected_loc; + LP geodetic_loc; + + geodetic_loc.u = x[point_offset*i]; + geodetic_loc.v = y[point_offset*i]; + + projected_loc = pj_fwd( geodetic_loc, dstdefn ); + if( pj_errno != 0 ) + return pj_errno; + + x[point_offset*i] = projected_loc.u; + y[point_offset*i] = projected_loc.v; + } + } + + return 0; +} + + + +// convert decimal degress to radians +void to_rad(POINT3D *pts, int num_points) +{ + int t; + for(t=0;tvl_len +1-4); + memcpy(input_proj4, input_proj4_text->vl_dat, + input_proj4_text->vl_len-4); + input_proj4[input_proj4_text->vl_len-4] = 0; //null terminate + + output_proj4 = (char *) palloc(output_proj4_text->vl_len +1-4); + memcpy(output_proj4, output_proj4_text->vl_dat, + output_proj4_text->vl_len-4); + output_proj4[output_proj4_text->vl_len-4] = 0; //null terminate + + //make input and output projection objects + input_pj = make_project(input_proj4); + if ( (input_pj == NULL) || pj_errno) + { + pfree(input_proj4); pfree(output_proj4); + PG_FREE_IF_COPY(geom, 0); + elog(ERROR,"tranform: couldnt parse proj4 input string"); + PG_RETURN_NULL(); + } + + output_pj = make_project(output_proj4); + if ((output_pj == NULL)|| pj_errno) + { + pfree(input_proj4); pfree(output_proj4); + pj_free(input_pj); + PG_FREE_IF_COPY(geom, 0); + elog(ERROR,"tranform: couldnt parse proj4 output string"); + PG_RETURN_NULL(); + } + + //great, now we have a geometry, and input/output PJ* structs. + //Excellent. + + + // clean up + pj_free(input_pj); + pj_free(output_pj); + pfree(input_proj4); pfree(output_proj4); + + elog(ERROR, "Not implemented yet"); + + PG_RETURN_POINTER(result); // new geometry +} + +PG_FUNCTION_INFO_V1(postgis_proj_version); +Datum postgis_proj_version(PG_FUNCTION_ARGS) +{ + const char *ver = pj_release; + text *result; + result = (text *) palloc(VARHDRSZ + strlen(ver)); + VARATT_SIZEP(result) = VARHDRSZ + strlen(ver) ; + memcpy(VARDATA(result), ver, strlen(ver)); + PG_RETURN_POINTER(result); +} + +#endif + -- 2.40.0