|
@@ -78,6 +78,7 @@ int input_wkt(char *wktfile)
|
|
{
|
|
{
|
|
FILE *infd;
|
|
FILE *infd;
|
|
char buff[8000];
|
|
char buff[8000];
|
|
|
|
+ OGRSpatialReferenceH hSRS;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
if (strcmp(wktfile, "-") == 0)
|
|
if (strcmp(wktfile, "-") == 0)
|
|
@@ -100,6 +101,28 @@ int input_wkt(char *wktfile)
|
|
ret = GPJ_wkt_to_grass(&cellhd, &projinfo, &projunits, buff, 0);
|
|
ret = GPJ_wkt_to_grass(&cellhd, &projinfo, &projunits, buff, 0);
|
|
set_default_region();
|
|
set_default_region();
|
|
|
|
|
|
|
|
+ hSRS = OSRNewSpatialReference(buff);
|
|
|
|
+ if (hSRS) {
|
|
|
|
+ const char *authkey, *authname, *authcode;
|
|
|
|
+
|
|
|
|
+ authkey = NULL;
|
|
|
|
+ if (OSRIsProjected(hSRS))
|
|
|
|
+ authkey = "PROJCS";
|
|
|
|
+ else if (OSRIsGeographic(hSRS))
|
|
|
|
+ authkey = "GEOGCS";
|
|
|
|
+
|
|
|
|
+ if (authkey) {
|
|
|
|
+ authname = OSRGetAuthorityName(hSRS, authkey);
|
|
|
|
+ if (authname && *authname && strcmp(authname, "EPSG") == 0) {
|
|
|
|
+ authcode = OSRGetAuthorityCode(hSRS, authkey);
|
|
|
|
+ if (authcode && *authcode) {
|
|
|
|
+ projepsg = G_create_key_value();
|
|
|
|
+ G_set_key_value("epsg", authcode, projepsg);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -171,6 +194,7 @@ int input_proj4(char *proj4params)
|
|
int input_epsg(int epsg_num)
|
|
int input_epsg(int epsg_num)
|
|
{
|
|
{
|
|
OGRSpatialReferenceH hSRS;
|
|
OGRSpatialReferenceH hSRS;
|
|
|
|
+ char epsgstr[100];
|
|
int ret = 0;
|
|
int ret = 0;
|
|
|
|
|
|
/* Set finder function for locating OGR csv co-ordinate system tables */
|
|
/* Set finder function for locating OGR csv co-ordinate system tables */
|
|
@@ -182,6 +206,10 @@ int input_epsg(int epsg_num)
|
|
|
|
|
|
ret = GPJ_osr_to_grass(&cellhd, &projinfo, &projunits, hSRS, 0);
|
|
ret = GPJ_osr_to_grass(&cellhd, &projinfo, &projunits, hSRS, 0);
|
|
|
|
|
|
|
|
+ sprintf(epsgstr, "%d", epsg_num);
|
|
|
|
+ projepsg = G_create_key_value();
|
|
|
|
+ G_set_key_value("epsg", epsgstr, projepsg);
|
|
|
|
+
|
|
OSRDestroySpatialReference(hSRS);
|
|
OSRDestroySpatialReference(hSRS);
|
|
|
|
|
|
set_default_region();
|
|
set_default_region();
|
|
@@ -211,6 +239,7 @@ int input_epsg(int epsg_num)
|
|
int input_georef(char *geofile)
|
|
int input_georef(char *geofile)
|
|
{
|
|
{
|
|
OGRDataSourceH ogr_ds;
|
|
OGRDataSourceH ogr_ds;
|
|
|
|
+ OGRSpatialReferenceH hSRS;
|
|
int ret = 0;
|
|
int ret = 0;
|
|
|
|
|
|
/* Try opening file with OGR first because it doesn't output a
|
|
/* Try opening file with OGR first because it doesn't output a
|
|
@@ -218,16 +247,16 @@ int input_georef(char *geofile)
|
|
G_message(_("Trying to open with OGR..."));
|
|
G_message(_("Trying to open with OGR..."));
|
|
OGRRegisterAll();
|
|
OGRRegisterAll();
|
|
|
|
|
|
|
|
+ hSRS = NULL;
|
|
if ((ogr_ds = OGROpen(geofile, FALSE, NULL))
|
|
if ((ogr_ds = OGROpen(geofile, FALSE, NULL))
|
|
&& (OGR_DS_GetLayerCount(ogr_ds) > 0)) {
|
|
&& (OGR_DS_GetLayerCount(ogr_ds) > 0)) {
|
|
OGRLayerH ogr_layer;
|
|
OGRLayerH ogr_layer;
|
|
- OGRSpatialReferenceH ogr_srs;
|
|
|
|
|
|
|
|
G_message(_("...succeeded."));
|
|
G_message(_("...succeeded."));
|
|
/* Get the first layer */
|
|
/* Get the first layer */
|
|
ogr_layer = OGR_DS_GetLayer(ogr_ds, 0);
|
|
ogr_layer = OGR_DS_GetLayer(ogr_ds, 0);
|
|
- ogr_srs = OGR_L_GetSpatialRef(ogr_layer);
|
|
|
|
- ret = GPJ_osr_to_grass(&cellhd, &projinfo, &projunits, ogr_srs, 0);
|
|
|
|
|
|
+ hSRS = OGR_L_GetSpatialRef(ogr_layer);
|
|
|
|
+ ret = GPJ_osr_to_grass(&cellhd, &projinfo, &projunits, hSRS, 0);
|
|
set_default_region();
|
|
set_default_region();
|
|
|
|
|
|
OGR_DS_Destroy(ogr_ds);
|
|
OGR_DS_Destroy(ogr_ds);
|
|
@@ -249,6 +278,7 @@ int input_georef(char *geofile)
|
|
0);
|
|
0);
|
|
|
|
|
|
set_gdal_region(gdal_ds);
|
|
set_gdal_region(gdal_ds);
|
|
|
|
+ hSRS = OSRNewSpatialReference(wktstring);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
G_fatal_error(_("Could not read georeferenced file %s using "
|
|
G_fatal_error(_("Could not read georeferenced file %s using "
|
|
@@ -260,6 +290,27 @@ int input_georef(char *geofile)
|
|
"projection information. 'XY (unprojected)' will be used"),
|
|
"projection information. 'XY (unprojected)' will be used"),
|
|
geofile);
|
|
geofile);
|
|
|
|
|
|
|
|
+ if (hSRS) {
|
|
|
|
+ const char *authkey, *authname, *authcode;
|
|
|
|
+
|
|
|
|
+ authkey = NULL;
|
|
|
|
+ if (OSRIsProjected(hSRS))
|
|
|
|
+ authkey = "PROJCS";
|
|
|
|
+ else if (OSRIsGeographic(hSRS))
|
|
|
|
+ authkey = "GEOGCS";
|
|
|
|
+
|
|
|
|
+ if (authkey) {
|
|
|
|
+ authname = OSRGetAuthorityName(hSRS, authkey);
|
|
|
|
+ if (authname && *authname && strcmp(authname, "EPSG") == 0) {
|
|
|
|
+ authcode = OSRGetAuthorityCode(hSRS, authkey);
|
|
|
|
+ if (authcode && *authcode) {
|
|
|
|
+ projepsg = G_create_key_value();
|
|
|
|
+ G_set_key_value("epsg", authcode, projepsg);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
}
|
|
}
|