Skip to content

Commit c1b360b

Browse files
author
cfarmer
committedNov 8, 2009
Fix crashes due to geometry pointers in QgsGeometryAnalyzer; Add QgsOverlayAnalyzer to analysis library (currently only supports intersections)
git-svn-id: http://svn.osgeo.org/qgis/trunk@12040 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3c81073 commit c1b360b

File tree

5 files changed

+441
-48
lines changed

5 files changed

+441
-48
lines changed
 

‎python/analysis/analysis.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
%Import core/core.sip
99

1010
%Include qgsgeometryanalyzer.sip
11+
%Include qgsoverlayanalyzer.sip
1112

‎src/analysis/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SET(QGIS_ANALYSIS_SRCS
3131
raster/qgstotalcurvaturefilter.cpp
3232
vector/qgsgeometryanalyzer.cpp
3333
vector/qgszonalstatistics.cpp
34+
vector/qgsoverlayanalyzer.cpp
3435
)
3536

3637
SET(QGIS_ANALYSIS_MOC_HDRS
@@ -43,6 +44,7 @@ INCLUDE_DIRECTORIES(
4344
${CMAKE_CURRENT_SOURCE_DIR}
4445
${CMAKE_CURRENT_SOURCE_DIR}/../core/
4546
${CMAKE_CURRENT_SOURCE_DIR}/../core/renderer
47+
${CMAKE_CURRENT_SOURCE_DIR}/../core/spatialindex
4648
interpolation
4749
${PROJ_INCLUDE_DIR}
4850
${GEOS_INCLUDE_DIR}
@@ -99,7 +101,7 @@ INSTALL(TARGETS qgis_analysis
99101

100102
# Added by Tim to install headers
101103

102-
SET(QGIS_ANALYSIS_HDRS vector/qgsgeometryanalyzer.h vector/qgszonalstatistics.h
104+
SET(QGIS_ANALYSIS_HDRS vector/qgsgeometryanalyzer.h vector/qgszonalstatistics.h vector/qgsgeometryanalyzer.h
103105
)
104106

105107
INSTALL(CODE "MESSAGE(\"Installing ANALYSIS headers...\")")

‎src/analysis/vector/qgsgeometryanalyzer.cpp

Lines changed: 128 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ bool QgsGeometryAnalyzer::extent( QgsVectorLayer* layer, const QString& shapefil
329329
QList<double> QgsGeometryAnalyzer::simpleMeasure( QgsGeometry* mpGeometry )
330330
{
331331
QList<double> list;
332+
double perim;
332333
if ( mpGeometry->wkbType() == QGis::WKBPoint )
333334
{
334335
QgsPoint pt = mpGeometry->asPoint();
@@ -341,11 +342,11 @@ QList<double> QgsGeometryAnalyzer::simpleMeasure( QgsGeometry* mpGeometry )
341342
list.append( measure.measure( mpGeometry ) );
342343
if ( mpGeometry->type() == QGis::Polygon )
343344
{
344-
list.append( perimeterMeasure( mpGeometry, measure ) );
345+
perim = perimeterMeasure( mpGeometry, measure );
346+
list.append( perim );
345347
}
346348
}
347349
return list;
348-
349350
}
350351

351352
double QgsGeometryAnalyzer::perimeterMeasure( QgsGeometry* geometry, QgsDistanceArea& measure )
@@ -383,51 +384,90 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
383384
{
384385
return false;
385386
}
386-
387387
QgsVectorDataProvider* dp = layer->dataProvider();
388388
if ( !dp )
389389
{
390390
return false;
391391
}
392+
bool useField = false;
393+
if ( uniqueIdField == -1 )
394+
{
395+
uniqueIdField = 0;
396+
}
397+
else
398+
{
399+
useField = true;
400+
}
401+
QgsFieldMap fields;
402+
fields.insert( 0 , QgsField( QString( "UID" ), QVariant::String ) );
403+
fields.insert( 1 , QgsField( QString( "AREA" ), QVariant::Double ) );
404+
fields.insert( 2 , QgsField( QString( "PERIM" ), QVariant::Double ) );
392405

393406
QGis::WkbType outputType = QGis::WKBPolygon;
394407
const QgsCoordinateReferenceSystem crs = layer->srs();
395408

396-
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), dp->fields(), outputType, &crs );
409+
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), fields, outputType, &crs );
397410
QgsFeature currentFeature;
398411
QgsGeometry* dissolveGeometry; //dissolve geometry
399412
QMultiMap<QString, int> map;
400-
bool useField = false;
401413

402-
if ( uniqueIdField == -1 )
414+
if ( onlySelectedFeatures )
403415
{
404-
uniqueIdField = 0;
416+
//use QgsVectorLayer::featureAtId
417+
const QgsFeatureIds selection = layer->selectedFeaturesIds();
418+
QgsFeatureIds::const_iterator it = selection.constBegin();
419+
for ( ; it != selection.constEnd(); ++it )
420+
{
421+
// if ( p )
422+
// {
423+
// p->setValue( processedFeatures );
424+
// }
425+
// if ( p && p->wasCanceled() )
426+
// {
427+
// // break; // it may be better to do something else here?
428+
// return false;
429+
// }
430+
if ( !layer->featureAtId( *it, currentFeature, true, true ) )
431+
{
432+
continue;
433+
}
434+
map.insert( currentFeature.attributeMap()[ uniqueIdField ].toString(), currentFeature.id() );
435+
}
405436
}
406437
else
407438
{
408-
useField = true;
409439
layer->select( layer->pendingAllAttributesList(), QgsRectangle(), true, false );
410440
while ( layer->nextFeature( currentFeature ) )
411441
{
412-
map.insert( currentFeature.attributeMap()[uniqueIdField].toString(), currentFeature.id() );
442+
// if ( p )
443+
// {
444+
// p->setValue( processedFeatures );
445+
// }
446+
// if ( p && p->wasCanceled() )
447+
// {
448+
// // break; // it may be better to do something else here?
449+
// return false;
450+
// }
451+
map.insert( currentFeature.attributeMap()[ uniqueIdField ].toString(), currentFeature.id() );
413452
}
414453
}
415-
QMultiMap<QString, int>::const_iterator jt;
416-
for (jt = map.constBegin(); jt != map.constEnd(); ++jt)
454+
455+
QMultiMap<QString, int>::const_iterator jt = map.constBegin();
456+
while ( jt != map.constEnd() )
417457
{
418458
QString currentKey = jt.key();
419459
int processedFeatures = 0;
420460
//take only selection
421461
if ( onlySelectedFeatures )
422462
{
423463
//use QgsVectorLayer::featureAtId
424-
const QgsFeatureIds selection = layer->selectedFeaturesIds();
464+
const QgsFeatureIds selection = layer->selectedFeaturesIds();
425465
if ( p )
426466
{
427-
p->setMaximum( selection.size() );
467+
p->setMaximum( selection.size() );
428468
}
429469
processedFeatures = 0;
430-
while ( jt != map.end() && ( jt.key() == currentKey || !useField ) )
470+
while ( jt != map.constEnd() && ( jt.key() == currentKey || !useField ) )
431471
{
432472
if ( p && p->wasCanceled() )
433473
{
@@ -437,18 +477,26 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
437477
{
438478
if ( p )
439479
{
440-
p->setValue( processedFeatures );
480+
p->setValue( processedFeatures );
441481
}
442482
if ( !layer->featureAtId( jt.value(), currentFeature, true, true ) )
443483
{
444-
continue;
484+
continue;
445485
}
446486
convexFeature( currentFeature, processedFeatures, &dissolveGeometry );
447487
++processedFeatures;
448488
}
449489
++jt;
450490
}
491+
QList<double> values;
492+
dissolveGeometry = dissolveGeometry->convexHull();
493+
values = simpleMeasure( dissolveGeometry );
494+
QgsAttributeMap attributeMap;
495+
attributeMap.insert( 0 , QVariant( currentKey ) );
496+
attributeMap.insert( 1 , values[ 0 ] );
497+
attributeMap.insert( 2 , values[ 1 ] );
451498
QgsFeature dissolveFeature;
499+
dissolveFeature.setAttributeMap( attributeMap );
452500
dissolveFeature.setGeometry( dissolveGeometry );
453501
vWriter.addFeature( dissolveFeature );
454502
}
@@ -461,7 +509,7 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
461509
p->setMaximum( featureCount );
462510
}
463511
processedFeatures = 0;
464-
while ( jt != map.end() && ( jt.key() == currentKey || !useField ) )
512+
while ( jt != map.constEnd() && ( jt.key() == currentKey || !useField ) )
465513
{
466514
if ( p )
467515
{
@@ -480,9 +528,19 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
480528
++processedFeatures;
481529
++jt;
482530
}
483-
QgsFeature dissolveFeature;
484-
dissolveFeature.setGeometry( dissolveGeometry );
485-
vWriter.addFeature( dissolveFeature );
531+
QList<double> values;
532+
// QgsGeometry* tmpGeometry = 0;
533+
dissolveGeometry = dissolveGeometry->convexHull();
534+
// values = simpleMeasure( tmpGeometry );
535+
values = simpleMeasure( dissolveGeometry );
536+
QgsAttributeMap attributeMap;
537+
attributeMap.insert( 0 , QVariant( currentKey ) );
538+
attributeMap.insert( 1 , QVariant( values[ 0 ] ) );
539+
attributeMap.insert( 2 , QVariant( values[ 1 ] ) );
540+
QgsFeature dissolveFeature;
541+
dissolveFeature.setAttributeMap( attributeMap );
542+
dissolveFeature.setGeometry( dissolveGeometry );
543+
vWriter.addFeature( dissolveFeature );
486544
}
487545
}
488546
return true;
@@ -522,51 +580,69 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
522580
{
523581
return false;
524582
}
525-
526583
QgsVectorDataProvider* dp = layer->dataProvider();
527584
if ( !dp )
528585
{
529586
return false;
530587
}
588+
bool useField = false;
589+
if ( uniqueIdField == -1 )
590+
{
591+
uniqueIdField = 0;
592+
}
593+
else
594+
{
595+
useField = true;
596+
}
531597

532598
QGis::WkbType outputType = dp->geometryType();
533599
const QgsCoordinateReferenceSystem crs = layer->srs();
534600

535601
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), dp->fields(), outputType, &crs );
536602
QgsFeature currentFeature;
537-
QgsGeometry* dissolveGeometry; //dissolve geometry
538603
QMultiMap<QString, int> map;
539-
bool useField = false;
540604

541-
if ( uniqueIdField == -1 )
605+
if ( onlySelectedFeatures )
542606
{
543-
uniqueIdField = 0;
607+
//use QgsVectorLayer::featureAtId
608+
const QgsFeatureIds selection = layer->selectedFeaturesIds();
609+
QgsFeatureIds::const_iterator it = selection.constBegin();
610+
for ( ; it != selection.constEnd(); ++it )
611+
{
612+
if ( !layer->featureAtId( *it, currentFeature, true, true ) )
613+
{
614+
continue;
615+
}
616+
map.insert( currentFeature.attributeMap()[ uniqueIdField ].toString(), currentFeature.id() );
617+
}
544618
}
545619
else
546620
{
547-
useField = true;
548621
layer->select( layer->pendingAllAttributesList(), QgsRectangle(), true, false );
549622
while ( layer->nextFeature( currentFeature ) )
550623
{
551-
map.insert( currentFeature.attributeMap()[uniqueIdField].toString(), currentFeature.id() );
624+
map.insert( currentFeature.attributeMap()[ uniqueIdField ].toString(), currentFeature.id() );
552625
}
553626
}
554-
QMultiMap<QString, int>::const_iterator jt;
555-
for (jt = map.constBegin(); jt != map.constEnd(); ++jt)
627+
628+
QgsGeometry* dissolveGeometry; //dissolve geometry
629+
QMultiMap<QString, int>::const_iterator jt = map.constBegin();
630+
QgsFeature outputFeature;
631+
while ( jt != map.constEnd() )
556632
{
557633
QString currentKey = jt.key();
558634
int processedFeatures = 0;
635+
bool first = true;
559636
//take only selection
560637
if ( onlySelectedFeatures )
561638
{
562639
//use QgsVectorLayer::featureAtId
563-
const QgsFeatureIds selection = layer->selectedFeaturesIds();
640+
const QgsFeatureIds selection = layer->selectedFeaturesIds();
564641
if ( p )
565642
{
566-
p->setMaximum( selection.size() );
643+
p->setMaximum( selection.size() );
567644
}
568-
processedFeatures = 0;
569-
while ( jt != map.end() && ( jt.key() == currentKey || !useField ) )
645+
while ( jt != map.constEnd() && ( jt.key() == currentKey || !useField ) )
570646
{
571647
if ( p && p->wasCanceled() )
572648
{
@@ -576,20 +652,22 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
576652
{
577653
if ( p )
578654
{
579-
p->setValue( processedFeatures );
655+
p->setValue( processedFeatures );
580656
}
581657
if ( !layer->featureAtId( jt.value(), currentFeature, true, true ) )
582658
{
583-
continue;
659+
continue;
660+
}
661+
if ( first )
662+
{
663+
outputFeature.setAttributeMap( currentFeature.attributeMap() );
664+
first = false;
584665
}
585666
dissolveFeature( currentFeature, processedFeatures, &dissolveGeometry );
586667
++processedFeatures;
587668
}
588669
++jt;
589670
}
590-
QgsFeature dissolveFeature;
591-
dissolveFeature.setGeometry( dissolveGeometry );
592-
vWriter.addFeature( dissolveFeature );
593671
}
594672
//take all features
595673
else
@@ -599,8 +677,7 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
599677
{
600678
p->setMaximum( featureCount );
601679
}
602-
processedFeatures = 0;
603-
while ( jt != map.end() && ( jt.key() == currentKey || !useField ) )
680+
while ( jt != map.constEnd() && ( jt.key() == currentKey || !useField ) )
604681
{
605682
if ( p )
606683
{
@@ -615,22 +692,24 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
615692
{
616693
continue;
617694
}
695+
{
696+
outputFeature.setAttributeMap( currentFeature.attributeMap() );
697+
first = false;
698+
}
618699
dissolveFeature( currentFeature, processedFeatures, &dissolveGeometry );
619700
++processedFeatures;
620701
++jt;
621702
}
622-
QgsFeature dissolveFeature;
623-
dissolveFeature.setGeometry( dissolveGeometry );
624-
vWriter.addFeature( dissolveFeature );
625703
}
704+
outputFeature.setGeometry( dissolveGeometry );
705+
vWriter.addFeature( outputFeature );
626706
}
627707
return true;
628708
}
629709

630710
void QgsGeometryAnalyzer::dissolveFeature( QgsFeature& f, int nProcessedFeatures, QgsGeometry** dissolveGeometry )
631711
{
632712
QgsGeometry* featureGeometry = f.geometry();
633-
QgsGeometry* tmpGeometry = 0;
634713

635714
if ( !featureGeometry )
636715
{
@@ -639,13 +718,15 @@ void QgsGeometryAnalyzer::dissolveFeature( QgsFeature& f, int nProcessedFeatures
639718

640719
if ( nProcessedFeatures == 0 )
641720
{
642-
*dissolveGeometry = featureGeometry;
721+
int geomSize = featureGeometry->wkbSize();
722+
*dissolveGeometry = new QgsGeometry();
723+
unsigned char* wkb = new unsigned char[geomSize];
724+
memcpy(wkb, featureGeometry->asWkb(), geomSize);
725+
(*dissolveGeometry)->fromWkb(wkb, geomSize);
643726
}
644727
else
645728
{
646-
tmpGeometry = *dissolveGeometry;
647729
*dissolveGeometry = ( *dissolveGeometry )->combine( featureGeometry );
648-
delete tmpGeometry;
649730
}
650731
}
651732

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/***************************************************************************
2+
qgsoverlayanalyzer.cpp - QGIS Tools for vector geometry analysis
3+
-------------------
4+
begin : 8 Nov 2009
5+
copyright : (C) Carson J. Q. Farmer
6+
email : carson.farmer@gmail.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id: qgis.h 9774 2008-12-12 05:41:24Z timlinux $ */
18+
19+
#include "qgsoverlayanalyzer.h"
20+
21+
#include "qgsapplication.h"
22+
#include "qgsfield.h"
23+
#include "qgsfeature.h"
24+
#include "qgslogger.h"
25+
#include "qgscoordinatereferencesystem.h"
26+
#include "qgsvectorfilewriter.h"
27+
#include "qgsvectordataprovider.h"
28+
#include "qgsdistancearea.h"
29+
#include <QProgressDialog>
30+
31+
bool QgsOverlayAnalyzer::intersection( QgsVectorLayer* layerA, QgsVectorLayer* layerB,
32+
const QString& shapefileName, bool onlySelectedFeatures,
33+
QProgressDialog* p )
34+
{
35+
if ( !layerA && !layerB )
36+
{
37+
return false;
38+
}
39+
40+
QgsVectorDataProvider* dpA = layerA->dataProvider();
41+
QgsVectorDataProvider* dpB = layerB->dataProvider();
42+
if ( !dpA && !dpB )
43+
{
44+
return false;
45+
}
46+
47+
QGis::WkbType outputType = dpA->geometryType();
48+
const QgsCoordinateReferenceSystem crs = layerA->srs();
49+
QgsFieldMap fields;
50+
//fields = combineFieldLists( dpA->fields(), dpB->fields() );
51+
52+
QgsVectorFileWriter vWriter( shapefileName, dpA->encoding(), fields, outputType, &crs );
53+
QgsFeature currentFeature;
54+
QgsGeometry* dissolveGeometry; //dissolve geometry (if dissolve enabled)
55+
QgsSpatialIndex index;
56+
57+
//take only selection
58+
if ( onlySelectedFeatures )
59+
{
60+
const QgsFeatureIds selectionB = layerB->selectedFeaturesIds();
61+
QgsFeatureIds::const_iterator it = selectionB.constBegin();
62+
for ( ; it != selectionB.constEnd(); ++it )
63+
{
64+
if ( !layerB->featureAtId( *it, currentFeature, true, true ) )
65+
{
66+
continue;
67+
}
68+
index.insertFeature( currentFeature );
69+
}
70+
//use QgsVectorLayer::featureAtId
71+
const QgsFeatureIds selectionA = layerA->selectedFeaturesIds();
72+
if ( p )
73+
{
74+
p->setMaximum( selectionA.size() );
75+
}
76+
77+
int processedFeatures = 0;
78+
it = selectionA.constBegin();
79+
for ( ; it != selectionA.constEnd(); ++it )
80+
{
81+
if ( p )
82+
{
83+
p->setValue( processedFeatures );
84+
}
85+
86+
if ( p && p->wasCanceled() )
87+
{
88+
break;
89+
}
90+
if ( !layerA->featureAtId( *it, currentFeature, true, true ) )
91+
{
92+
continue;
93+
}
94+
intersectFeature( currentFeature, &vWriter, layerB, &index );
95+
++processedFeatures;
96+
}
97+
98+
if ( p )
99+
{
100+
p->setValue( selectionA.size() );
101+
}
102+
}
103+
//take all features
104+
else
105+
{
106+
layerB->select( layerB->pendingAllAttributesList(), QgsRectangle(), true, false );
107+
while ( dpB->nextFeature( currentFeature ) )
108+
{
109+
index.insertFeature( currentFeature );
110+
}
111+
112+
layerA->select( layerA->pendingAllAttributesList(), QgsRectangle(), true, false );
113+
114+
int featureCount = layerA->featureCount();
115+
if ( p )
116+
{
117+
p->setMaximum( featureCount );
118+
}
119+
int processedFeatures = 0;
120+
121+
while ( layerA->nextFeature( currentFeature ) )
122+
{
123+
if ( p )
124+
{
125+
p->setValue( processedFeatures );
126+
}
127+
if ( p && p->wasCanceled() )
128+
{
129+
break;
130+
}
131+
intersectFeature( currentFeature, &vWriter, layerB, &index );
132+
++processedFeatures;
133+
}
134+
if ( p )
135+
{
136+
p->setValue( featureCount );
137+
}
138+
}
139+
return true;
140+
}
141+
142+
void QgsOverlayAnalyzer::intersectFeature( QgsFeature& f, QgsVectorFileWriter* vfw,
143+
QgsVectorLayer* vl, QgsSpatialIndex* index )
144+
{
145+
QgsGeometry* featureGeometry = f.geometry();
146+
QgsGeometry* intersectGeometry = 0;
147+
QgsFeature currentFeature;
148+
149+
if ( !featureGeometry )
150+
{
151+
return;
152+
}
153+
154+
QList<int> intersects;
155+
intersects = index->intersects( featureGeometry->boundingBox() );
156+
QList<int>::const_iterator it = intersects.constBegin();
157+
for ( ; it != intersects.constEnd(); ++it )
158+
{
159+
if ( !vl->featureAtId( *it, currentFeature, true, true ) )
160+
{
161+
continue;
162+
}
163+
164+
if ( featureGeometry->intersects( currentFeature.geometry() ) )
165+
{
166+
intersectGeometry = featureGeometry->intersection( currentFeature.geometry() );
167+
168+
QgsFeature outFeature;
169+
outFeature.setGeometry( intersectGeometry );
170+
outFeature.setAttributeMap( f.attributeMap() );
171+
172+
//add it to vector file writer
173+
if ( vfw )
174+
{
175+
vfw->addFeature( outFeature );
176+
}
177+
}
178+
}
179+
}
180+
181+
void QgsOverlayAnalyzer::combineFieldLists( QgsFieldMap fieldListA, QgsFieldMap fieldListB )
182+
{
183+
QMap<int, QgsField>::const_iterator i = fieldListB.constBegin();
184+
int count = 0;
185+
while ( i != fieldListB.constEnd() )
186+
{
187+
if ( !fieldListA.contains( i.key() ) )
188+
{
189+
fieldListA.insert( fieldListA.size()-1, i.value() );
190+
count = 0;
191+
}
192+
else
193+
{
194+
QgsField field;
195+
field = i.value();
196+
QString name = field.name();
197+
name.append( "_" ).append( QString( count ) );
198+
fieldListA.insert( fieldListA.size()-1 , QgsField( name, field.type() ) );
199+
++count;
200+
continue;
201+
}
202+
++i;
203+
}
204+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/***************************************************************************
2+
qgsoverlayanalyzer.h - QGIS Tools for vector geometry analysis
3+
-------------------
4+
begin : 19 March 2009
5+
copyright : (C) Carson Farmer
6+
email : carson.farmer@gmail.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id: qgis.h 9774 2008-12-12 05:41:24Z timlinux $ */
18+
19+
#ifndef QGSOVERLAYANALYZERH
20+
#define QGSOVERLAYANALYZERH
21+
22+
#include "qgsvectorlayer.h"
23+
#include "qgsfield.h"
24+
#include "qgsspatialindex.h"
25+
#include "qgsfeature.h"
26+
#include "qgsgeometry.h"
27+
#include "qgsfield.h"
28+
#include "qgsdistancearea.h"
29+
30+
class QgsVectorFileWriter;
31+
class QProgressDialog;
32+
33+
34+
/** \ingroup analysis
35+
* The QGis class provides vector overlay analysis functions
36+
*/
37+
38+
class ANALYSIS_EXPORT QgsOverlayAnalyzer
39+
{
40+
public:
41+
42+
/**Perform an intersection on two input vector layers and write output to a new shape file
43+
@param layerA input vector layer
44+
@param layerB input vector layer
45+
@param shapefileName path to the output shp
46+
@param onlySelectedFeatures if true, only selected features are considered, else all the features
47+
@param p progress dialog (or 0 if no progress dialog is to be shown)
48+
@note: added in version 1.4*/
49+
bool intersection( QgsVectorLayer* layerA, QgsVectorLayer* layerB, \
50+
const QString& shapefileName, bool onlySelectedFeatures = false, \
51+
QProgressDialog* p = 0 );
52+
53+
// /**Perform a union of two input vector layers and write output to a new shape file
54+
// @param layerA input vector layer
55+
// @param layerB input vector layer
56+
// @param shapefileName path to the output shp
57+
// @param onlySelectedFeatures if true, only selected features are considered, else all the features
58+
// @param p progress dialog (or 0 if no progress dialog is to be shown)
59+
// @note: added in version 1.4*/
60+
// bool combine( QgsVectorLayer* layerA, QgsVectorLayer* layerB,
61+
// const QString& shapefileName, bool onlySelectedFeatures = false,
62+
// QProgressDialog* p = 0 );
63+
//
64+
// /**Clip a vector layer based on the boundary of another vector layer and
65+
// write output to a new shape file
66+
// @param layerA input vector layer
67+
// @param layerB input vector layer
68+
// @param shapefileName path to the output shp
69+
// @param onlySelectedFeatures if true, only selected features are considered, else all the features
70+
// @param p progress dialog (or 0 if no progress dialog is to be shown)
71+
// @note: added in version 1.4*/
72+
// bool clip( QgsVectorLayer* layerA, QgsVectorLayer* layerB,
73+
// const QString& shapefileName, bool onlySelectedFeatures = false,
74+
// QProgressDialog* p = 0 );
75+
//
76+
// /**Difference a vector layer based on the geometries of another vector layer
77+
// and write the output to a new shape file
78+
// @param layerA input vector layer
79+
// @param layerB input vector layer
80+
// @param shapefileName path to the output shp
81+
// @param onlySelectedFeatures if true, only selected features are considered, else all the features
82+
// @param p progress dialog (or 0 if no progress dialog is to be shown)
83+
// @note: added in version 1.4*/
84+
// bool difference( QgsVectorLayer* layerA, QgsVectorLayer* layerB,
85+
// const QString& shapefileName, bool onlySelectedFeatures = false,
86+
// QProgressDialog* p = 0 );
87+
//
88+
// /**Intersect two vector layers and write the geometries of each layer that
89+
// do not intersect with the other layer to a new shape file (Symmetrical difference)
90+
// @param layerA input vector layer
91+
// @param layerB input vector layer
92+
// @param shapefileName path to the output shp
93+
// @param onlySelectedFeatures if true, only selected features are considered, else all the features
94+
// @param p progress dialog (or 0 if no progress dialog is to be shown)
95+
// @note: added in version 1.4*/
96+
// bool symDifference( QgsVectorLayer* layerA, QgsVectorLayer* layerB,
97+
// const QString& shapefileName, bool onlySelectedFeatures = false,
98+
// QProgressDialog* p = 0 );
99+
100+
private:
101+
102+
void combineFieldLists( QgsFieldMap fieldListA, QgsFieldMap fieldListB );
103+
void intersectFeature( QgsFeature& f, QgsVectorFileWriter* vfw, QgsVectorLayer* dp, QgsSpatialIndex* index );
104+
};
105+
#endif //QGSVECTORANALYZER

0 commit comments

Comments
 (0)
Please sign in to comment.