Move lwproj_from_string from libpgcommon to liblwgeom [RT-SIGTA]

git-svn-id: http://svn.osgeo.org/postgis/trunk@7741 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Sandro Santilli 2011-08-12 19:18:46 +00:00
parent 9e0173b08b
commit a7e6fe6c36
5 changed files with 63 additions and 52 deletions

View file

@ -14,7 +14,7 @@ CC = @CC@
CFLAGS = @CFLAGS@ @PICFLAGS@ @WARNFLAGS@ \
@GEOS_CPPFLAGS@ -DPOSTGIS_GEOS_VERSION=@POSTGIS_GEOS_VERSION@ \
@PROJ_CPPFLAGS@ -DPOSTGIS_PROJ_VERSION=@POSTGIS_PROJ_VERSION@
LDFLAGS = @GEOS_LDFLAGS@ @PROJ_LDFLAGS@ -lgeos_c
LDFLAGS = @GEOS_LDFLAGS@ -lgeos_c @PROJ_LDFLAGS@ -lproj
NUMERICFLAGS = @NUMERICFLAGS@
top_builddir = @top_builddir@
prefix = @prefix@

View file

@ -2191,6 +2191,14 @@ LWGEOM* lwgeom_sharedpaths(const LWGEOM* geom1, const LWGEOM* geom2);
/*******************************************************************************
* PROJ4-dependent extra functions on LWGEOM
******************************************************************************/
/**
* Get a projection from a string representation
*
* Eg: "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
*/
projPJ lwproj_from_string(const char* txt);
/**
* Transform (reproject) a geometry in-place.
* @param geom the geometry to transform

View file

@ -13,6 +13,7 @@
#include "proj_api.h"
#include "liblwgeom.h"
#include <math.h>
#include <string.h>
/** convert decimal degress to radians */
@ -149,3 +150,56 @@ point4d_transform(POINT4D *pt, projPJ srcpj, projPJ dstpj)
if (pj_is_latlong(dstpj)) to_dec(pt);
return 1;
}
projPJ
lwproj_from_string(const char *str1)
{
int t;
char *params[1024]; /* one for each parameter */
char *loc;
char *str;
size_t slen;
projPJ result;
if (str1 == NULL) return NULL;
slen = strlen(str1);
if (slen == 0) return NULL;
str = lwalloc(slen+1);
strcpy(str, str1);
/*
* first we split the string into a bunch of smaller strings,
* based on the " " separator
*/
params[0] = str; /* 1st param, we'll null terminate at the " " soon */
loc = str;
t = 1;
while ((loc != NULL) && (*loc != 0) )
{
loc = strchr(loc, ' ');
if (loc != NULL)
{
*loc = 0; /* null terminate */
params[t] = loc+1;
loc++; /* next char */
t++; /*next param */
}
}
if (!(result=pj_init(t, params)))
{
lwfree(str);
return NULL;
}
lwfree(str);
return result;
}

View file

@ -36,7 +36,6 @@ Datum postgis_proj_version(PG_FUNCTION_ARGS);
#include "utils/hsearch.h"
#include "lwgeom_transform.h"
projPJ lwproj_from_string(char *str1);
int pj_transform_nodatum(projPJ srcdefn, projPJ dstdefn, long point_count, int point_offset, double *x, double *y, double *z );
@ -627,55 +626,6 @@ void SetPROJ4LibPath(void)
/** given a string, make a PJ object */
projPJ
lwproj_from_string(char *str1)
{
int t;
char *params[1024]; /* one for each parameter */
char *loc;
char *str;
projPJ result;
if (str1 == NULL) return NULL;
if (strlen(str1) == 0) return NULL;
str = pstrdup(str1);
/*
* first we split the string into a bunch of smaller strings,
* based on the " " separator
*/
params[0] = str; /* 1st param, we'll null terminate at the " " soon */
loc = str;
t = 1;
while ((loc != NULL) && (*loc != 0) )
{
loc = strchr(loc, ' ');
if (loc != NULL)
{
*loc = 0; /* null terminate */
params[t] = loc+1;
loc++; /* next char */
t++; /*next param */
}
}
if (!(result=pj_init(t, params)))
{
pfree(str);
return NULL;
}
pfree(str);
return result;
}
Proj4Cache GetPROJ4Cache(FunctionCallInfoData *fcinfo) {
return (Proj4Cache)GetPROJ4SRSCache(fcinfo) ;
}

View file

@ -15,7 +15,6 @@
#include "lwgeom_pg.h"
#include "proj_api.h"
projPJ lwproj_from_string(char *str1);
char* GetProj4StringSPI(int srid);
/**