Skip to content

Commit

Permalink
wm(t)s json identify: allow geometryless feature info
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 3, 2014
1 parent 2f41ad2 commit aaf6b71
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2637,24 +2637,27 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
if ( result.property( "type" ).toString() != "FeatureCollection" )
throw QString( "type FeatureCollection expected: %1" ).arg( result.property( "type" ).toString() );

QString crsType = result.property( "crs" ).property( "type" ).toString();
QString crsText;
if ( crsType == "name" )
crsText = result.property( "crs" ).property( "name" ).toString();
else if ( crsType == "EPSG" )
crsText = QString( "%1:%2" ).arg( crsType ).arg( result.property( "crs" ).property( "properties" ).property( "code" ).toString() );
else
QgsDebugMsg( QString( "crs not supported:%1" ).arg( result.property( "crs" ).toString() ) );

QgsCoordinateReferenceSystem featuresCrs;
featuresCrs.createFromOgcWmsCrs( crsText );

if ( !featuresCrs.isValid() )
throw QString( "CRS %1 invalid" ).arg( crsText );

if ( featuresCrs.isValid() && featuresCrs != crs() )
if ( result.property( "crs" ).isValid() )
{
coordinateTransform = new QgsCoordinateTransform( featuresCrs, crs() );
QString crsType = result.property( "crs" ).property( "type" ).toString();
QString crsText;
if ( crsType == "name" )
crsText = result.property( "crs" ).property( "name" ).toString();
else if ( crsType == "EPSG" )
crsText = QString( "%1:%2" ).arg( crsType ).arg( result.property( "crs" ).property( "properties" ).property( "code" ).toString() );
else
QgsDebugMsg( QString( "crs not supported:%1" ).arg( result.property( "crs" ).toString() ) );

QgsCoordinateReferenceSystem featuresCrs;
featuresCrs.createFromOgcWmsCrs( crsText );

if ( !featuresCrs.isValid() )
throw QString( "CRS %1 invalid" ).arg( crsText );

if ( featuresCrs.isValid() && featuresCrs != crs() )
{
coordinateTransform = new QgsCoordinateTransform( featuresCrs, crs() );
}
}

QScriptValue fc = result.property( "features" );
Expand Down Expand Up @@ -2683,22 +2686,25 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs

QgsFeature feature( fields );

QScriptValue geom = json_stringify.call( QScriptValue(), QScriptValueList() << f.property( "geometry" ) );
if ( geom.isString() )
if ( !f.property( "geometry" ).isNull() )
{
OGRGeometryH ogrGeom = OGR_G_CreateGeometryFromJson( geom.toString().toUtf8() );
if ( ogrGeom )
QScriptValue geom = json_stringify.call( QScriptValue(), QScriptValueList() << f.property( "geometry" ) );
if ( geom.isString() )
{
size_t wkbSize = OGR_G_WkbSize( ogrGeom );
unsigned char *wkb = new unsigned char[ wkbSize ];
OGR_G_ExportToWkb( ogrGeom, ( OGRwkbByteOrder ) QgsApplication::endian(), wkb );
OGR_G_DestroyGeometry( ogrGeom );
OGRGeometryH ogrGeom = OGR_G_CreateGeometryFromJson( geom.toString().toUtf8() );
if ( ogrGeom )
{
size_t wkbSize = OGR_G_WkbSize( ogrGeom );
unsigned char *wkb = new unsigned char[ wkbSize ];
OGR_G_ExportToWkb( ogrGeom, ( OGRwkbByteOrder ) QgsApplication::endian(), wkb );
OGR_G_DestroyGeometry( ogrGeom );

feature.setGeometryAndOwnership( wkb, wkbSize );
feature.setGeometryAndOwnership( wkb, wkbSize );

if ( coordinateTransform && feature.geometry() )
{
feature.geometry()->transform( *coordinateTransform );
if ( coordinateTransform && feature.geometry() )
{
feature.geometry()->transform( *coordinateTransform );
}
}
}
}
Expand Down

0 comments on commit aaf6b71

Please sign in to comment.