void QgsGml::startElement( const XML_Char* el, const XML_Char** attr ) { QString elementName( QString::fromUtf8( el ) ); ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.top() ); QStringList splitName = elementName.split( NS_SEPARATOR ); QString localName = splitName.last(); QString ns = splitName.size() > 1 ? splitName.first() : ""; if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "coordinates" ) { mParseModeStack.push( QgsGml::coordinate ); mCoorMode = QgsGml::coordinate; mStringCash.clear(); mCoordinateSeparator = readAttribute( "cs", attr ); if ( mCoordinateSeparator.isEmpty() ) { mCoordinateSeparator = ","; } mTupleSeparator = readAttribute( "ts", attr ); if ( mTupleSeparator.isEmpty() ) { mTupleSeparator = " "; } } if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "pos" || elementName == GML_NAMESPACE + NS_SEPARATOR + "posList" ) { mParseModeStack.push( QgsGml::posList ); mCoorMode = QgsGml::posList; mStringCash.clear(); QString dimension = readAttribute( "srsDimension", attr ); bool ok; mDimension = dimension.toInt( &ok ); if ( dimension.isEmpty() || !ok ) { mDimension = 2; } } else if ( localName == mGeometryAttribute ) { mParseModeStack.push( QgsGml::geometry ); } //else if ( mParseModeStack.size() == 0 && elementName == GML_NAMESPACE + NS_SEPARATOR + "boundedBy" ) else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "boundedBy" ) { mParseModeStack.push( QgsGml::boundingBox ); } else if ( theParseMode == none && localName == mTypeName ) { Q_ASSERT( !mCurrentFeature ); mCurrentFeature = new QgsFeature( mFeatureCount ); QgsAttributes attributes( mThematicAttributes.size() ); //add empty attributes mCurrentFeature->setAttributes( attributes ); mParseModeStack.push( QgsGml::feature ); mCurrentFeatureId = readAttribute( "fid", attr ); } else if ( theParseMode == boundingBox && elementName == GML_NAMESPACE + NS_SEPARATOR + "Box" ) { //read attribute srsName="EPSG:26910" int epsgNr; if ( readEpsgFromAttribute( epsgNr, attr ) != 0 ) { QgsDebugMsg( "error, could not get epsg id" ); } } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "Polygon" ) { mCurrentWKBFragments.push_back( QList<unsigned char*>() ); mCurrentWKBFragmentSizes.push_back( QList<int>() ); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiPoint" ) { mParseModeStack.push( QgsGml::multiPoint ); //we need one nested list for intermediate WKB mCurrentWKBFragments.push_back( QList<unsigned char*>() ); mCurrentWKBFragmentSizes.push_back( QList<int>() ); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiLineString" ) { mParseModeStack.push( QgsGml::multiLine ); //we need one nested list for intermediate WKB mCurrentWKBFragments.push_back( QList<unsigned char*>() ); mCurrentWKBFragmentSizes.push_back( QList<int>() ); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiPolygon" ) { mParseModeStack.push( QgsGml::multiPolygon ); } else if ( theParseMode == feature && mThematicAttributes.contains( localName ) ) { mParseModeStack.push( QgsGml::attribute ); mAttributeName = localName; mStringCash.clear(); } // QGIS server (2.2) is using: // <Attribute value="My description" name="desc"/> else if ( theParseMode == feature && localName.compare( "attribute", Qt::CaseInsensitive ) == 0 ) { QString name = readAttribute( "name", attr ); if ( mThematicAttributes.contains( name ) ) { QString value = readAttribute( "value", attr ); setAttribute( name, value ); } } if ( mEpsg == 0 && ( localName == "Point" || localName == "MultiPoint" || localName == "LineString" || localName == "MultiLineString" || localName == "Polygon" || localName == "MultiPolygon" ) ) { if ( readEpsgFromAttribute( mEpsg, attr ) != 0 ) { QgsDebugMsg( "error, could not get epsg id" ); } else { QgsDebugMsg( QString( "mEpsg = %1" ).arg( mEpsg ) ); } } }
void QgsGml::endElement( const XML_Char* el ) { QString elementName( QString::fromUtf8( el ) ); ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.top() ); QStringList splitName = elementName.split( NS_SEPARATOR ); QString localName = splitName.last(); QString ns = splitName.size() > 1 ? splitName.first() : ""; if (( theParseMode == coordinate && elementName == GML_NAMESPACE + NS_SEPARATOR + "coordinates" ) || ( theParseMode == posList && ( elementName == GML_NAMESPACE + NS_SEPARATOR + "pos" || elementName == GML_NAMESPACE + NS_SEPARATOR + "posList" ) ) ) { mParseModeStack.pop(); } else if ( theParseMode == attribute && localName == mAttributeName ) //add a thematic attribute to the feature { mParseModeStack.pop(); setAttribute( mAttributeName, mStringCash ); } else if ( theParseMode == geometry && localName == mGeometryAttribute ) { mParseModeStack.pop(); } else if ( theParseMode == boundingBox && elementName == GML_NAMESPACE + NS_SEPARATOR + "boundedBy" ) { //create bounding box from mStringCash if ( createBBoxFromCoordinateString( mCurrentExtent, mStringCash ) != 0 ) { QgsDebugMsg( "creation of bounding box failed" ); } mParseModeStack.pop(); } else if ( theParseMode == feature && localName == mTypeName ) { Q_ASSERT( mCurrentFeature ); if ( mCurrentWKBSize > 0 ) { mCurrentFeature->setGeometryAndOwnership( mCurrentWKB, mCurrentWKBSize ); } else if ( !mCurrentExtent.isEmpty() ) { mCurrentFeature->setGeometry( QgsGeometry::fromRect( mCurrentExtent ) ); } else { mCurrentFeature->setGeometry( 0 ); } mCurrentFeature->setValid( true ); mFeatures.insert( mCurrentFeature->id(), mCurrentFeature ); if ( !mCurrentFeatureId.isEmpty() ) { mIdMap.insert( mCurrentFeature->id(), mCurrentFeatureId ); } mCurrentFeature = 0; ++mFeatureCount; mParseModeStack.pop(); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "Point" ) { QList<QgsPoint> pointList; if ( pointsFromString( pointList, mStringCash ) != 0 ) { //error } if ( pointList.count() == 0 ) return; // error if ( theParseMode == QgsGml::geometry ) { //directly add WKB point to the feature if ( getPointWKB( &mCurrentWKB, &mCurrentWKBSize, *( pointList.begin() ) ) != 0 ) { //error } if ( *mWkbType != QGis::WKBMultiPoint ) //keep multitype in case of geometry type mix { *mWkbType = QGis::WKBPoint; } } else //multipoint, add WKB as fragment { unsigned char* wkb = 0; int wkbSize = 0; QList<unsigned char*> wkbList; QList<int> wkbSizeList; if ( getPointWKB( &wkb, &wkbSize, *( pointList.begin() ) ) != 0 ) { //error } if ( !mCurrentWKBFragments.isEmpty() ) { mCurrentWKBFragments.last().push_back( wkb ); mCurrentWKBFragmentSizes.last().push_back( wkbSize ); } else { QgsDebugMsg( "No wkb fragments" ); } } } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "LineString" ) { //add WKB point to the feature QList<QgsPoint> pointList; if ( pointsFromString( pointList, mStringCash ) != 0 ) { //error } if ( theParseMode == QgsGml::geometry ) { if ( getLineWKB( &mCurrentWKB, &mCurrentWKBSize, pointList ) != 0 ) { //error } if ( *mWkbType != QGis::WKBMultiLineString )//keep multitype in case of geometry type mix { *mWkbType = QGis::WKBLineString; } } else //multiline, add WKB as fragment { unsigned char* wkb = 0; int wkbSize = 0; QList<unsigned char*> wkbList; QList<int> wkbSizeList; if ( getLineWKB( &wkb, &wkbSize, pointList ) != 0 ) { //error } if ( !mCurrentWKBFragments.isEmpty() ) { mCurrentWKBFragments.last().push_back( wkb ); mCurrentWKBFragmentSizes.last().push_back( wkbSize ); } else { QgsDebugMsg( "no wkb fragments" ); } } } else if (( theParseMode == geometry || theParseMode == multiPolygon ) && elementName == GML_NAMESPACE + NS_SEPARATOR + "LinearRing" ) { QList<QgsPoint> pointList; if ( pointsFromString( pointList, mStringCash ) != 0 ) { //error } unsigned char* wkb = 0; int wkbSize = 0; if ( getRingWKB( &wkb, &wkbSize, pointList ) != 0 ) { //error } if ( !mCurrentWKBFragments.isEmpty() ) { mCurrentWKBFragments.last().push_back( wkb ); mCurrentWKBFragmentSizes.last().push_back( wkbSize ); } else { QgsDebugMsg( "no wkb fragments" ); } } else if (( theParseMode == geometry || theParseMode == multiPolygon ) && elementName == GML_NAMESPACE + NS_SEPARATOR + "Polygon" ) { if ( *mWkbType != QGis::WKBMultiPolygon )//keep multitype in case of geometry type mix { *mWkbType = QGis::WKBPolygon; } if ( theParseMode == geometry ) { createPolygonFromFragments(); } } else if ( theParseMode == multiPoint && elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiPoint" ) { *mWkbType = QGis::WKBMultiPoint; mParseModeStack.pop(); createMultiPointFromFragments(); } else if ( theParseMode == multiLine && elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiLineString" ) { *mWkbType = QGis::WKBMultiLineString; mParseModeStack.pop(); createMultiLineFromFragments(); } else if ( theParseMode == multiPolygon && elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiPolygon" ) { *mWkbType = QGis::WKBMultiPolygon; mParseModeStack.pop(); createMultiPolygonFromFragments(); } }
void QgsGml::startElement( const XML_Char* el, const XML_Char** attr ) { QString elementName( QString::fromUtf8( el ) ); ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.top() ); QStringList splitName = elementName.split( NS_SEPARATOR ); QString localName = splitName.last(); QString ns = splitName.size() > 1 ? splitName.first() : ""; if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "coordinates" ) { mParseModeStack.push( QgsGml::coordinate ); mStringCash.clear(); mCoordinateSeparator = readAttribute( "cs", attr ); if ( mCoordinateSeparator.isEmpty() ) { mCoordinateSeparator = ","; } mTupleSeparator = readAttribute( "ts", attr ); if ( mTupleSeparator.isEmpty() ) { mTupleSeparator = " "; } } else if ( localName == mGeometryAttribute ) { mParseModeStack.push( QgsGml::geometry ); } //else if ( mParseModeStack.size() == 0 && elementName == GML_NAMESPACE + NS_SEPARATOR + "boundedBy" ) else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "boundedBy" ) { mParseModeStack.push( QgsGml::boundingBox ); } else if ( theParseMode == none && localName == mTypeName ) { Q_ASSERT( !mCurrentFeature ); mCurrentFeature = new QgsFeature( mFeatureCount ); QgsAttributes attributes( mThematicAttributes.size() ); //add empty attributes mCurrentFeature->setAttributes( attributes ); mParseModeStack.push( QgsGml::feature ); mCurrentFeatureId = readAttribute( "fid", attr ); } else if ( theParseMode == boundingBox && elementName == GML_NAMESPACE + NS_SEPARATOR + "Box" ) { //read attribute srsName="EPSG:26910" int epsgNr; if ( readEpsgFromAttribute( epsgNr, attr ) != 0 ) { QgsDebugMsg( "error, could not get epsg id" ); } } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "Polygon" ) { mCurrentWKBFragments.push_back( QList<unsigned char*>() ); mCurrentWKBFragmentSizes.push_back( QList<int>() ); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiPoint" ) { mParseModeStack.push( QgsGml::multiPoint ); //we need one nested list for intermediate WKB mCurrentWKBFragments.push_back( QList<unsigned char*>() ); mCurrentWKBFragmentSizes.push_back( QList<int>() ); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiLineString" ) { mParseModeStack.push( QgsGml::multiLine ); //we need one nested list for intermediate WKB mCurrentWKBFragments.push_back( QList<unsigned char*>() ); mCurrentWKBFragmentSizes.push_back( QList<int>() ); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiPolygon" ) { mParseModeStack.push( QgsGml::multiPolygon ); } else if ( theParseMode == feature && mThematicAttributes.contains( localName ) ) { mParseModeStack.push( QgsGml::attribute ); mAttributeName = localName; mStringCash.clear(); } }