Skip to content

Commit aaf6b71

Browse files
committedMar 3, 2014
wm(t)s json identify: allow geometryless feature info
1 parent 2f41ad2 commit aaf6b71

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed
 

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,24 +2637,27 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
26372637
if ( result.property( "type" ).toString() != "FeatureCollection" )
26382638
throw QString( "type FeatureCollection expected: %1" ).arg( result.property( "type" ).toString() );
26392639

2640-
QString crsType = result.property( "crs" ).property( "type" ).toString();
2641-
QString crsText;
2642-
if ( crsType == "name" )
2643-
crsText = result.property( "crs" ).property( "name" ).toString();
2644-
else if ( crsType == "EPSG" )
2645-
crsText = QString( "%1:%2" ).arg( crsType ).arg( result.property( "crs" ).property( "properties" ).property( "code" ).toString() );
2646-
else
2647-
QgsDebugMsg( QString( "crs not supported:%1" ).arg( result.property( "crs" ).toString() ) );
2648-
2649-
QgsCoordinateReferenceSystem featuresCrs;
2650-
featuresCrs.createFromOgcWmsCrs( crsText );
2651-
2652-
if ( !featuresCrs.isValid() )
2653-
throw QString( "CRS %1 invalid" ).arg( crsText );
2654-
2655-
if ( featuresCrs.isValid() && featuresCrs != crs() )
2640+
if ( result.property( "crs" ).isValid() )
26562641
{
2657-
coordinateTransform = new QgsCoordinateTransform( featuresCrs, crs() );
2642+
QString crsType = result.property( "crs" ).property( "type" ).toString();
2643+
QString crsText;
2644+
if ( crsType == "name" )
2645+
crsText = result.property( "crs" ).property( "name" ).toString();
2646+
else if ( crsType == "EPSG" )
2647+
crsText = QString( "%1:%2" ).arg( crsType ).arg( result.property( "crs" ).property( "properties" ).property( "code" ).toString() );
2648+
else
2649+
QgsDebugMsg( QString( "crs not supported:%1" ).arg( result.property( "crs" ).toString() ) );
2650+
2651+
QgsCoordinateReferenceSystem featuresCrs;
2652+
featuresCrs.createFromOgcWmsCrs( crsText );
2653+
2654+
if ( !featuresCrs.isValid() )
2655+
throw QString( "CRS %1 invalid" ).arg( crsText );
2656+
2657+
if ( featuresCrs.isValid() && featuresCrs != crs() )
2658+
{
2659+
coordinateTransform = new QgsCoordinateTransform( featuresCrs, crs() );
2660+
}
26582661
}
26592662

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

26842687
QgsFeature feature( fields );
26852688

2686-
QScriptValue geom = json_stringify.call( QScriptValue(), QScriptValueList() << f.property( "geometry" ) );
2687-
if ( geom.isString() )
2689+
if ( !f.property( "geometry" ).isNull() )
26882690
{
2689-
OGRGeometryH ogrGeom = OGR_G_CreateGeometryFromJson( geom.toString().toUtf8() );
2690-
if ( ogrGeom )
2691+
QScriptValue geom = json_stringify.call( QScriptValue(), QScriptValueList() << f.property( "geometry" ) );
2692+
if ( geom.isString() )
26912693
{
2692-
size_t wkbSize = OGR_G_WkbSize( ogrGeom );
2693-
unsigned char *wkb = new unsigned char[ wkbSize ];
2694-
OGR_G_ExportToWkb( ogrGeom, ( OGRwkbByteOrder ) QgsApplication::endian(), wkb );
2695-
OGR_G_DestroyGeometry( ogrGeom );
2694+
OGRGeometryH ogrGeom = OGR_G_CreateGeometryFromJson( geom.toString().toUtf8() );
2695+
if ( ogrGeom )
2696+
{
2697+
size_t wkbSize = OGR_G_WkbSize( ogrGeom );
2698+
unsigned char *wkb = new unsigned char[ wkbSize ];
2699+
OGR_G_ExportToWkb( ogrGeom, ( OGRwkbByteOrder ) QgsApplication::endian(), wkb );
2700+
OGR_G_DestroyGeometry( ogrGeom );
26962701

2697-
feature.setGeometryAndOwnership( wkb, wkbSize );
2702+
feature.setGeometryAndOwnership( wkb, wkbSize );
26982703

2699-
if ( coordinateTransform && feature.geometry() )
2700-
{
2701-
feature.geometry()->transform( *coordinateTransform );
2704+
if ( coordinateTransform && feature.geometry() )
2705+
{
2706+
feature.geometry()->transform( *coordinateTransform );
2707+
}
27022708
}
27032709
}
27042710
}

0 commit comments

Comments
 (0)
Please sign in to comment.