Skip to content
Permalink
Browse files
Merge branch 'master' of https://github.com/qgis/Quantum-GIS
  • Loading branch information
volaya committed Feb 3, 2013
2 parents 93dbfd7 + 8a880ca commit 0995c0fa9f07715a52b1917857e48924cec95aad
@@ -304,24 +304,17 @@ IF (PEDANTIC)
ADD_DEFINITIONS( /wd4610 ) # user defined constructor required (sqlite3_index_info)
ADD_DEFINITIONS( /wd4706 ) # assignment within conditional expression (pal)
ELSE (MSVC)
IF (APPLE)
# add warnings via flags instead of definitions on Mac (otherwise -Wall can not be overridden per language)
SET(_warnings "-Wall -Wextra -Wno-long-long -Wformat-security -Wno-strict-aliasing")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_warnings}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_warnings}")
ELSE (APPLE)
ADD_DEFINITIONS( -Wall -Wextra -Wno-long-long -Wformat-security -Wno-strict-aliasing )
ENDIF (APPLE)
# add warnings via flags (not as definitions as on Mac -Wall can not be overridden per language )
SET(_warnings "-Wall -Wextra -Wno-long-long -Wformat-security -Wno-strict-aliasing")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_warnings}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_warnings}")

# Qt produces lots of warnings with strict aliasing (as of Qt 4.4.0 & GCC 4.3)
# There are redundant declarations in Qt and GDAL
# ADD_DEFINITIONS( -fstrict-aliasing -Wstrict-aliasing=1 -Wredundant-decls )

IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF (APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage")
ELSE (APPLE)
ADD_DEFINITIONS(-Wno-return-type-c-linkage) # used in plugins and providers
ENDIF (APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage")
ENDIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
ENDIF (MSVC)

@@ -32,6 +32,7 @@ ifneq (,$(findstring $(DISTRIBUTION),"lucid"))
TESTMAKE += ARGS="-E PyQgsRectangle"
endif


QGIS_MAJOR=$(shell sed -ne 's/SET(CPACK_PACKAGE_VERSION_MAJOR "\([0-9]*\)")/\1/p' CMakeLists.txt)
QGIS_MINOR=$(shell sed -ne 's/SET(CPACK_PACKAGE_VERSION_MINOR "\([0-9]*\)")/\1/p' CMakeLists.txt)
QGIS_PATCH=$(shell sed -ne 's/SET(CPACK_PACKAGE_VERSION_PATCH "\([0-9]*\)")/\1/p' CMakeLists.txt)
@@ -57,7 +58,7 @@ ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
MAKEFLAGS += -j$(NUMJOBS)
endif

ifneq (,$(findstring $(DISTRIBUTION),"squeeze wheezy lucid maverick natty oneiric precise"))
ifneq (,$(findstring $(DISTRIBUTION),"squeeze wheezy lucid maverick natty oneiric precise raring"))
CMAKE_OPTS += -D WITH_PYSPATIALITE=TRUE
endif

@@ -72,7 +73,8 @@ else
endif

ifneq (,$(findstring $(DISTRIBUTION),"raring"))
CMAKE_OPTS += -D PYTHON_LIBRARY=/usr/lib/$(DEB_BUILD_GNU_TYPE)/libpython2.7.so
DEB_BUILD_MULTIARCH ?= $(shell dpkg-architecture -qDEB_BUILD_MULTIARCH)
CMAKE_OPTS += -D PYTHON_LIBRARY=/usr/lib/$(DEB_BUILD_MULTIARCH)/libpython2.7.so
endif

ifneq (,$(findstring -oracle,$(DISTRIBUTION)))
@@ -6747,7 +6747,7 @@ Bitte koorigieren Sie dies, da die OSM-Erweiterung nicht weiß welche Layer das
</message>
<message>
<source>Open script file</source>
<translation>Skiptdatei öffnen</translation>
<translation>Skriptdatei öffnen</translation>
</message>
<message>
<source>Save to script file</source>
@@ -111,7 +111,7 @@ class QgsFeature
const QgsAttributes& attributes() const;
//QgsAttributes& attributes();
void setAttributes(const QgsAttributes& attrs);
void setAttribute( int field, const QVariant& attr );
bool setAttribute( int field, const QVariant& attr );
void initAttributes( int fieldCount );

/**Deletes an attribute and its value*/
@@ -458,7 +458,7 @@ def extract_nodes( self ):

def polygons_to_lines( self ):
vprovider = self.vlayer.dataProvider()
writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviders.fields(),
writer = QgsVectorFileWriter( self.myName, self.myEncoding, vprovider.fields(),
QGis.WKBLineString, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
@@ -488,7 +488,7 @@ def polygons_to_lines( self ):

def lines_to_polygons( self ):
vprovider = self.vlayer.dataProvider()
writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviders.fields(),
writer = QgsVectorFileWriter( self.myName, self.myEncoding, vprovider.fields(),
QGis.WKBPolygon, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
@@ -545,47 +545,45 @@ def export_geometry_info( self ):
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0)
self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, vprovider.featureCount() ) )

( fields, index1, index2 ) = self.checkMeasurementFields( self.vlayer, not self.writeShape )

if self.writeShape:
( fields, index1, index2 ) = self.checkGeometryFields( self.vlayer )
writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
vprovider.geometryType(), vprovider.crs() )
fit = vprovider.getFeatures()
while fit.nextFeature(inFeat):
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement )
nElement += 1
inGeom = inFeat.geometry()

if self.myCalcType == 1:
inGeom.transform( coordTransform )
fit = vprovider.getFeatures()
while fit.nextFeature(inFeat):
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement )
nElement += 1
inGeom = inFeat.geometry()

if self.myCalcType == 1:
inGeom.transform( coordTransform )

( attr1, attr2 ) = self.simpleMeasure( inGeom, self.myCalcType, ellips, crs )
( attr1, attr2 ) = self.simpleMeasure( inGeom, self.myCalcType, ellips, crs )

if self.writeShape:
outFeat.setGeometry( inGeom )
atMap = inFeat.attributes()
maxIndex = index1 if index1>index2 else index2
if maxIndex>len(atMap):
atMap += [ QVariant() ] * ( index2+1 - len(atMap) )
atMap[ index1 ] = attr1
if index1!=index2:
atMap[ index2 ] = attr2
outFeat.setAttributes( atMap )
outFeat.addAttribute( index1, QVariant( attr1 ) )
outFeat.addAttribute( index2, QVariant( attr2 ) )
writer.addFeature( outFeat )
del writer
return True
else: # update existing file
( index1, index2 ) = self.findOrCreateFields( self.vlayer )

fit = vprovider.getFeatures()
while fit.nextFeature(inFeat):
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement )
nElement += 1
inGeom = inFeat.geometry()

if self.myCalcType == 1:
inGeom.transform( coordTransform )
( attr1, attr2 ) = self.simpleMeasure( inGeom, self.myCalcType, ellips, crs )

else:
changeMap = {}
changeAttributeMap = { index1 : QVariant( attr1 ),
index2 : QVariant( attr2 ) }
changeMap[ inFeat.id() ] = changeAttributeMap
changeMap[ inFeat.id() ] = {}
changeMap[ inFeat.id() ][ index1 ] = QVariant( attr1 )
if index1!=index2:
changeMap[ inFeat.id() ][ index2 ] = QVariant( attr2 )
vprovider.changeAttributeValues( changeMap )

if self.writeShape:
del writer

return True

def polygon_centroids( self ):
@@ -659,7 +657,7 @@ def delaunay_triangulation( self ):
geom = QgsGeometry( inFeat.geometry() )
point = QgsPoint( geom.asPoint() )
polygon.append( point )
if step <= 3: feat.addAttribute( step, QVariant( ids[ index ] ) )
if step <= 3: feat.setAttribute( step, QVariant( ids[ index ] ) )
step += 1
geometry = QgsGeometry().fromPolygon( [ polygon ] )
feat.setGeometry( geometry )
@@ -869,16 +867,16 @@ def feature_extent( self, ):

self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0 )

fields = { 0 : QgsField( "MINX", QVariant.Double ),
1 : QgsField( "MINY", QVariant.Double ),
2 : QgsField( "MAXX", QVariant.Double ),
3 : QgsField( "MAXY", QVariant.Double ),
4 : QgsField( "CNTX", QVariant.Double ),
5 : QgsField( "CNTY", QVariant.Double ),
6 : QgsField( "AREA", QVariant.Double ),
7 : QgsField( "PERIM", QVariant.Double ),
8 : QgsField( "HEIGHT", QVariant.Double ),
9 : QgsField( "WIDTH", QVariant.Double ) }
fields = [ QgsField( "MINX", QVariant.Double ),
QgsField( "MINY", QVariant.Double ),
QgsField( "MAXX", QVariant.Double ),
QgsField( "MAXY", QVariant.Double ),
QgsField( "CNTX", QVariant.Double ),
QgsField( "CNTY", QVariant.Double ),
QgsField( "AREA", QVariant.Double ),
QgsField( "PERIM", QVariant.Double ),
QgsField( "HEIGHT", QVariant.Double ),
QgsField( "WIDTH", QVariant.Double ) ]

writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
QGis.WKBPolygon, self.vlayer.crs() )
@@ -1000,170 +998,35 @@ def perimMeasure( self, inGeom, measure ):
value = value + measure.measureLine( k )
return value

def checkForField( self, L, e ):
e = QString( e ).toLower()
fieldRange = range( 0, len( L ) )
for item in fieldRange:
if L[ item ].toLower() == e:
return True, item
return False, len( L )
def doubleFieldIndex( self, name, desc, fieldList, f ):
i = 0
for f in fieldList:
if name == f.name().toUpper():
return (i, fieldList )
i += 1

def checkGeometryFields( self, vlayer ):
vprovider = vlayer.dataProvider()
nameList = []
fieldList = vprovider.fields()
geomType = vlayer.geometryType()
fieldKeys = fieldList.keys()

for i in fieldKeys:
nameList.append( fieldList[ i ].name().toLower() )
if geomType == QGis.Polygon:
if len( fieldKeys ) == max( fieldKeys ): # if equal, then the field geometry is not at the end of the fields list
( found, index ) = self.checkForField( nameList, "AREA" )
index1 = index + 1
else:
( found, index1 ) = self.checkForField( nameList, "AREA" )
if not found:
field = QgsField( "AREA", QVariant.Double, "double precision", 21, 6, self.tr( "Polygon area" ) )
if len( fieldKeys ) == max( fieldKeys ):
index1 = len( fieldList ) + 1
else:
index1 = len( fieldList )
fieldList[ index1 ] = field
if len( fieldKeys ) == max( fieldKeys ):
( found, index ) = self.checkForField( nameList, "PERIMETER" )
index2 = index + 1
else:
( found, index2 ) = self.checkForField( nameList, "PERIMETER" )
if not found:
field = QgsField( "PERIMETER", QVariant.Double, "double precision", 21, 6, self.tr( "Polygon perimeter" ) )
if len( fieldKeys ) == max( fieldKeys ):
index2 = len( fieldList ) + 1
else:
index2 = len( fieldList )
fieldList[ index2 ] = field
elif geomType == QGis.Line:
if len( fieldKeys ) == max( fieldKeys ):
( found, index ) = self.checkForField( nameList, "LENGTH" )
index1 = index + 1
else:
( found, index1 ) = self.checkForField( nameList, "LENGTH" )
if not found:
field = QgsField( "LENGTH", QVariant.Double, "double precision", 21, 6, self.tr( "Line length" ) )
if len( fieldKeys ) == max( fieldKeys ):
index1 = len( fieldList ) + 1
else:
index1 = len( fieldList )
fieldList[ index1 ] = field
index2 = index1
else:
if len( fieldKeys ) == max( fieldKeys ):
( found, index ) = self.checkForField( nameList, "XCOORD" )
index1 = index + 1
else:
( found, index1 ) = self.checkForField( nameList, "XCOORD" )
if not found:
field = QgsField( "XCOORD", QVariant.Double, "double precision", 21, 6, self.tr( "Point x coordinate" ) )
if len( fieldKeys ) == max( fieldKeys ):
index1 = len( fieldList ) + 1
else:
index1 = len( fieldList )
fieldList[ index1 ] = field

if len( fieldKeys ) == max( fieldKeys ):
( found, index ) = self.checkForField( nameList, "YCOORD" )
index2 = index + 1
else:
( found, index2 ) = self.checkForField( nameList, "YCOORD" )
if not found:
field = QgsField( "YCOORD", QVariant.Double, "double precision", 21, 6, self.tr( "Point y coordinate" ) )
if len( fieldKeys ) == max( fieldKeys ):
index2 = len( fieldList ) + 2
else:
index2 = len( fieldList )
fieldList[ index2 ] = field
return ( fieldList, index1, index2 )
fieldList.append( QgsField( name, QVariant.Double, "double precision", 21, 6, desc ) )
return ( len(fieldList)-1, fieldList )

def findOrCreateFields( self, vlayer ):
def checkMeasurementFields( self, vlayer, add ):
vprovider = vlayer.dataProvider()
fieldList = vprovider.fields()
geomType = vlayer.geometryType()
newFields = []
nameList = []
fieldKeys = fieldList.keys()

for i in fieldKeys:
nameList.append( fieldList[ i ].name().toLower() )

if geomType == QGis.Polygon:
if len( fieldKeys ) == max( fieldKeys ):
( found, index ) = self.checkForField( nameList, "AREA" )
index1 = index + 1
else:
( found, index1 ) = self.checkForField( nameList, "AREA" )
if not found:
field = QgsField( "AREA", QVariant.Double, "double precision", 21, 6, self.tr( "Polygon area" ) )
if len( fieldKeys ) == max( fieldKeys ):
index1 = len( fieldKeys ) + 1
else:
index1 = len( fieldKeys )
newFields.append( field )
if len( fieldKeys ) == max( fieldKeys ):
( found, index ) = self.checkForField( nameList, "PERIMETER" )
index1 = index + 1
else:
( found, index2 ) = self.checkForField( nameList, "PERIMETER" )
if not found:
field = QgsField( "PERIMETER", QVariant.Double, "double precision", 21, 6, self.tr( "Polygon perimeter" ) )
if len( fieldKeys ) == max( fieldKeys ):
index2 = len( fieldKeys ) + 2
else:
index2 = len( fieldKeys ) + 1
newFields.append( field )
(index1, fieldList) = doubleFieldIndex( "AREA", self.tr( "Polygon area" ), fieldList )
(index2, fieldList) = doubleFieldIndex( "PERIMETER", self.tr( "Polygon perimeter" ), fieldList )
elif geomType == QGis.Line:
if len( fieldKeys ) == max( fieldKeys ):
( found, index ) = self.checkForField( nameList, "LENGTH" )
index1 = index + 1
else:
( found, index1 ) = self.checkForField( nameList, "LENGTH" )
if not found:
field = QgsField( "LENGTH", QVariant.Double, "double precision", 21, 6, self.tr( "Line length" ) )
if len( fieldKeys ) == max( fieldKeys ):
index1 = len( fieldKeys ) + 1
else:
index1 = len( fieldKeys )
newFields.append( field )
(index1, fieldList) = doubleFieldIndex( "LENGTH", self.tr( "Line length" ), fieldList )
index2 = index1
else:
if len( fieldKeys ) == max( fieldKeys ):
( found, index ) = self.checkForField( nameList, "XCOORD" )
index1 = index + 1
else:
( found, index1 ) = self.checkForField( nameList, "XCOORD" )
if not found:
field = QgsField( "XCOORD", QVariant.Double, "double precision", 21, 6, self.tr( "Point x coordinate" ) )
if len( fieldKeys ) == max( fieldKeys ):
index = len( fieldKeys ) + 1
else:
index1 = len( fieldKeys )
newFields.append( field )
(index1, fieldList) = doubleFieldIndex( "XCOORD", self.tr( "Point x ordinate" ), fieldList )
(index2, fieldList) = doubleFieldIndex( "YCOORD", self.tr( "Point y ordinate" ), fieldList )

if len( fieldKeys ) == max( fieldKeys ):
( found, index ) = self.checkForField( nameList, "YCOORD" )
index2 = index + 1
else:
( found, index2 ) = self.checkForField( nameList, "YCOORD" )
if not found:
field = QgsField( "YCOORD", QVariant.Double, "double precision", 21, 6, self.tr( "Point y coordinate" ) )
if len( fieldKeys ) == max( fieldKeys ):
index2 = len( fieldKeys ) + 2
else:
index2 = len( fieldKeys ) + 1
newFields.append( field )
# FIXME: addAttributes was deprecated and removed
vprovider.addAttributes( newFields )
vlayer.updateFieldMap()
return ( index1, index2 )
if add:
vprovider.addAttributes( newFields )
vlayer.updateFieldMap()

return ( fieldList, index1, index2 )

def extractAsLine( self, geom ):
multi_geom = QgsGeometry()
Loading

0 comments on commit 0995c0f

Please sign in to comment.