[gdal-dev] vector representation in netcdf 4

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] vector representation in netcdf 4

Bekaert, David (334H)

Dear GDAL developers,

 

I am looking into adding a wkt compatible polygon into a netcdf (version 4) file which also has raster information in it.

Attached is a sample file generated by Even “mixed.nc” with a wkt polygon enclosed formatted as a string of numpy array.

The sample allows to extract a poly using ogr2ogr as “ogr2ogr mixed.shp mixed.nc poly”

 

Although QGIS does not seem to catch projection information.

Is there a standard way of storing vector information in netcdf conform CF or would the attached sample be specifically for GDAL only?

 

Thank you,

David

 


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

mixed.nc (71K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: vector representation in netcdf 4

Even Rouault-2
David,

No need to test with QGIS, ogrinfo also shows that the SRS isn't recognized.

This sample files was quickly hand generated with ncdump/ncgen without taking
much care to the georeferencing. It lacks referencing the transverse_mercator
variable in the vector fields.

Like:

        char ogc_wkt(record, ogc_wkt_max_width) ;
                ogc_wkt:long_name = "Geometry as ISO WKT" ;
                ogc_wkt:grid_mapping = "transverse_mercator" ;
        double AREA(record) ;
                AREA:long_name = "Field AREA" ;
                AREA:ogr_field_name = "AREA" ;
                AREA:ogr_field_type = "Real" ;
                AREA:ogr_field_width = 12 ;
                AREA:ogr_field_precision = 3 ;
                AREA:grid_mapping = "transverse_mercator" ;
        double EAS_ID(record) ;
                EAS_ID:long_name = "Field EAS_ID" ;
                EAS_ID:ogr_field_name = "EAS_ID" ;
                EAS_ID:ogr_field_type = "Integer64" ;
                EAS_ID:ogr_field_width = 11 ;
                EAS_ID:grid_mapping = "transverse_mercator" ;
        char PRFEDEA(record, PRFEDEA_max_width) ;
                PRFEDEA:long_name = "Field PRFEDEA" ;
                PRFEDEA:ogr_field_name = "PRFEDEA" ;
                PRFEDEA:ogr_field_type = "String" ;
                PRFEDEA:ogr_field_width = 16 ;
                PRFEDEA:grid_mapping = "transverse_mercator" ;

Actually I've just tried adding this and it works now. Modified file attached

Even

> Dear GDAL developers,
>
> I am looking into adding a wkt compatible polygon into a netcdf (version 4)
> file which also has raster information in it.
 Attached is a sample file
> generated by Even “mixed.nc” with a wkt polygon enclosed formatted as a
> string of numpy array. The sample allows to extract a poly using ogr2ogr as
> “ogr2ogr mixed.shp mixed.nc poly”
> Although QGIS does not seem to catch projection information.
> Is there a standard way of storing vector information in netcdf conform CF
> or would the attached sample be specifically for GDAL only?
 
> Thank you,
> David
>


--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

mixed.nc (71K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: vector representation in netcdf 4

Bekaert, David (334H)
Hi GDAL developers, Even,

Thanks for sharing the updated sample product with srs info included.

I was able to mimic you polygon formatting in the attached TEST.nc file.
Unfortunately I was not able to get the srs info captured in my shape file when applying ogr2ogr.
I am using the same crs I used successful used for 2D rasters in nc4 (longitude latitude).
When I turn the debug mode on it states it looks for a geoTransform when generating the shapefile.
I therefore added a dummy geoTransform to my crs but that did not make a difference.
I am unsure why this would be needed for a polygon, but saw your sample has one in there too.

Any idea what I might be doing incorrectly or should modify in my crs?
Below I include the commandline outputs.

Thank you for your help,
David


gdalinfo TEST.nc
Warning 1: dimension #1 (ogc_wkt_width) is not a Longitude/X dimension.
Warning 1: dimension #0 (record) is not a Latitude/Y dimension.
Warning 1: 1-pixel width/height files not supported, xdim: 191 ydim: 1
Driver: netCDF/Network Common Data Format
Files: TEST.nc
Size is 191, 1
Coordinate System is `'
Metadata:
  NC_GLOBAL#Conventions=CF-1.6
  NC_GLOBAL#ogr_geometry_field=ogc_wkt
  NC_GLOBAL#ogr_layer_name=poly
  NC_GLOBAL#ogr_layer_type=POLYGON
  ogc_wkt#grid_mapping=crs
  ogc_wkt#long_name=Geometry as ISO WKT
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,    1.0)
Upper Right (  191.0,    0.0)
Lower Right (  191.0,    1.0)
Center      (   95.5,    0.5)
Band 1 Block=191x1 Type=Byte, ColorInterp=Undefined
  NoData Value=0
  Metadata:
    grid_mapping=crs
    long_name=Geometry as ISO WKT
    NETCDF_VARNAME=ogc_wkt




ogr2ogr TEST.shp TEST.nc poly --config CPL_DEBUG on
GDAL_netCDF: driver detected file type=3, libnetcdf detected type=3
GDAL_netCDF: dim_count = 2
GDAL_netCDF: var_count = 2
GDAL_netCDF:
=====
SetProjectionFromVar( 0)
GDAL_netCDF: got grid_mapping crs
GDAL_netCDF: bIsGdalFile=0 bIsGdalCfFile=0 bBottomUp=1
GDAL_netCDF: got spheroid from CF: (6378137.000000 , 298.257224)
GDAL_netCDF: bGotGeogCS=1 bGotCfSRS=1 bGotCfGT=0 bGotGdalSRS=0 bGotGdalGT=0
GDAL_netCDF: did not get geotransform from CF nor GDAL!
GDAL: GDALOpen(TEST.nc, this=0x7fa035c3b060) succeeds as netCDF.
GDAL: Using ESRI Shapefile driver
GDAL: QuietDelete(TEST.shp) invoking Delete()
GDAL: GDALDriver::Create(ESRI Shapefile,TEST.shp,0,0,0,Unknown,0x0)
Shape: DBF Codepage = LDID/87 for TEST.shp
Shape: Treating as encoding 'ISO-8859-1'.
OGR: Created dummy FID field for shapefile since schema is empty.
GDALVectorTranslate: 1 features written in layer 'TEST'
GDAL: GDALClose(TEST.nc, this=0x7fa035c3b060)
GDAL: GDALClose(TEST.shp, this=0x7fa035c88ed0)



On 1/11/19, 2:11 PM, "Even Rouault" <[hidden email]> wrote:

    David,
   
    No need to test with QGIS, ogrinfo also shows that the SRS isn't recognized.
   
    This sample files was quickly hand generated with ncdump/ncgen without taking
    much care to the georeferencing. It lacks referencing the transverse_mercator
    variable in the vector fields.
   
    Like:
   
    char ogc_wkt(record, ogc_wkt_max_width) ;
    ogc_wkt:long_name = "Geometry as ISO WKT" ;
    ogc_wkt:grid_mapping = "transverse_mercator" ;
    double AREA(record) ;
    AREA:long_name = "Field AREA" ;
    AREA:ogr_field_name = "AREA" ;
    AREA:ogr_field_type = "Real" ;
    AREA:ogr_field_width = 12 ;
    AREA:ogr_field_precision = 3 ;
    AREA:grid_mapping = "transverse_mercator" ;
    double EAS_ID(record) ;
    EAS_ID:long_name = "Field EAS_ID" ;
    EAS_ID:ogr_field_name = "EAS_ID" ;
    EAS_ID:ogr_field_type = "Integer64" ;
    EAS_ID:ogr_field_width = 11 ;
    EAS_ID:grid_mapping = "transverse_mercator" ;
    char PRFEDEA(record, PRFEDEA_max_width) ;
    PRFEDEA:long_name = "Field PRFEDEA" ;
    PRFEDEA:ogr_field_name = "PRFEDEA" ;
    PRFEDEA:ogr_field_type = "String" ;
    PRFEDEA:ogr_field_width = 16 ;
    PRFEDEA:grid_mapping = "transverse_mercator" ;
   
    Actually I've just tried adding this and it works now. Modified file attached
   
    Even
   
    > Dear GDAL developers,
    >
    > I am looking into adding a wkt compatible polygon into a netcdf (version 4)
    > file which also has raster information in it.
     Attached is a sample file
    > generated by Even “mixed.nc” with a wkt polygon enclosed formatted as a
    > string of numpy array. The sample allows to extract a poly using ogr2ogr as
    > “ogr2ogr mixed.shp mixed.nc poly”
    > Although QGIS does not seem to catch projection information.
    > Is there a standard way of storing vector information in netcdf conform CF
    > or would the attached sample be specifically for GDAL only?
     
    > Thank you,
    > David
    >
   
   
    --
    Spatialys - Geospatial professional services
    http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

TEST.shp (326 bytes) Download Attachment
TEST.nc (17K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: vector representation in netcdf 4

Even Rouault-2
David,

>
> Thanks for sharing the updated sample product with srs info included.
>
> I was able to mimic you polygon formatting in the attached TEST.nc file.
> Unfortunately I was not able to get the srs info captured in my shape file
> when applying ogr2ogr.
> I am using the same crs I used successful used for
> 2D rasters in nc4 (longitude latitude). When I turn the debug mode on it
> states it looks for a geoTransform when generating the shapefile. I
> therefore added a dummy geoTransform to my crs but that did not make a
> difference. I am unsure why this would be needed for a polygon, but saw
> your sample has one in there too.
> Any idea what I might be doing incorrectly or should modify in my crs?
> Below I include the commandline outputs.

Several remarks:
- for the vector side, use ogrinfo for inspection. gdalinfo doesn't work for
me with the file you provided, which is expected since it is a vector one and
not a raster one, with 2.3.0 or above, so I suspect you might use a too old
version
- it appears the code require the crs variable to have a 'spatial_ref'
attribute with the WKT string and not 'crs_wkt'. Deducing the SRS from only CF
attributes (grid_mapping_name, longitude_of_prime_meridian, semi_major_axis,
inverse_flattening) isn't supported currently in the vector case, since the
code also expects x and y variables to be present.

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: vector representation in netcdf 4

Emilio Mayorga-2
FYI, until recently representation of vector geometries in netCDF-CF has not been standardized. But there's a mature proposal/spec in place for "simple geometries" that's close to being officially adopted by CF. See:

I believe there are sample data files and a Python implementation accessible on the github site.

This spec is implemented on the netcdf classic (netcdf 3) model. So, it doesn't use features that are specific to netcdf 4.

Cheers,
-Emilio


On Wed, Jan 16, 2019 at 12:32 AM Even Rouault <[hidden email]> wrote:
David,

>
> Thanks for sharing the updated sample product with srs info included.
>
> I was able to mimic you polygon formatting in the attached TEST.nc file.
> Unfortunately I was not able to get the srs info captured in my shape file
> when applying ogr2ogr.
> I am using the same crs I used successful used for
> 2D rasters in nc4 (longitude latitude). When I turn the debug mode on it
> states it looks for a geoTransform when generating the shapefile. I
> therefore added a dummy geoTransform to my crs but that did not make a
> difference. I am unsure why this would be needed for a polygon, but saw
> your sample has one in there too.
> Any idea what I might be doing incorrectly or should modify in my crs?
> Below I include the commandline outputs.

Several remarks:
- for the vector side, use ogrinfo for inspection. gdalinfo doesn't work for
me with the file you provided, which is expected since it is a vector one and
not a raster one, with 2.3.0 or above, so I suspect you might use a too old
version
- it appears the code require the crs variable to have a 'spatial_ref'
attribute with the WKT string and not 'crs_wkt'. Deducing the SRS from only CF
attributes (grid_mapping_name, longitude_of_prime_meridian, semi_major_axis,
inverse_flattening) isn't supported currently in the vector case, since the
code also expects x and y variables to be present.

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev