Skip to content

Commit 3e49a06

Browse files
author
cfarmer
committed
add new functions to analysis library, also adds python bindings to analysis library
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11976 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 1fea1f2 commit 3e49a06

File tree

7 files changed

+673
-522
lines changed

7 files changed

+673
-522
lines changed

python/CMakeLists.txt

+30-19
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,45 @@ SUBDIRS(plugins)
22
IF (WIN32)
33
SET(BINDINGS_CORE_LIB ${CMAKE_CURRENT_BINARY_DIR}/core/core.pyd)
44
SET(BINDINGS_GUI_LIB ${CMAKE_CURRENT_BINARY_DIR}/gui/gui.pyd)
5+
SET(BINDINGS_ANALYSIS_LIB ${CMAKE_CURRENT_BINARY_DIR}/analysis/analysis.pyd)
56
IF (NOT MSVC)
67
SET(QGIS_CORE_LIB ${CMAKE_BINARY_DIR}/src/core/libqgis_core.dll)
78
SET(QGIS_GUI_LIB ${CMAKE_BINARY_DIR}/src/gui/libqgis_gui.dll)
9+
SET(QGIS_ANALYSIS_LIB ${CMAKE_BINARY_DIR}/src/analysis/libqgis_analysis.dll)
810
ELSE (NOT MSVC)
9-
SET(QGIS_CORE_LIB ${CMAKE_BINARY_DIR}/src/core/${CMAKE_CFG_INTDIR}/qgis_core.lib)
10-
SET(QGIS_GUI_LIB ${CMAKE_BINARY_DIR}/src/gui/${CMAKE_CFG_INTDIR}/qgis_gui.lib)
11+
SET(QGIS_CORE_LIB ${CMAKE_BINARY_DIR}/src/core/${CMAKE_CFG_INTDIR}/qgis_core.lib)
12+
SET(QGIS_GUI_LIB ${CMAKE_BINARY_DIR}/src/gui/${CMAKE_CFG_INTDIR}/qgis_gui.lib)
13+
SET(QGIS_ANALYSIS_LIB ${CMAKE_BINARY_DIR}/src/analysis/${CMAKE_CFG_INTDIR}/qgis_analysis.lib)
1114
ENDIF (NOT MSVC)
1215
ELSE (WIN32)
13-
SET(BINDINGS_CORE_LIB ${CMAKE_CURRENT_BINARY_DIR}/core/core.so)
14-
SET(BINDINGS_GUI_LIB ${CMAKE_CURRENT_BINARY_DIR}/gui/gui.so)
16+
SET(BINDINGS_CORE_LIB ${CMAKE_CURRENT_BINARY_DIR}/core/core.so)
17+
SET(BINDINGS_GUI_LIB ${CMAKE_CURRENT_BINARY_DIR}/gui/gui.so)
18+
SET(BINDINGS_ANALYSIS_LIB ${CMAKE_CURRENT_BINARY_DIR}/analysis/analysis.so)
1519
IF (APPLE)
16-
SET(QGIS_CORE_LIB ${CMAKE_BINARY_DIR}/src/core/libqgis_core.dylib)
17-
SET(QGIS_GUI_LIB ${CMAKE_BINARY_DIR}/src/gui/libqgis_gui.dylib)
20+
SET(QGIS_CORE_LIB ${CMAKE_BINARY_DIR}/src/core/libqgis_core.dylib)
21+
SET(QGIS_GUI_LIB ${CMAKE_BINARY_DIR}/src/gui/libqgis_gui.dylib)
22+
SET(QGIS_ANALYSIS_LIB ${CMAKE_BINARY_DIR}/src/analysis/libqgis_analysis.dylib)
1823
ELSE (APPLE)
19-
SET(QGIS_CORE_LIB ${CMAKE_BINARY_DIR}/src/core/libqgis_core.so)
20-
SET(QGIS_GUI_LIB ${CMAKE_BINARY_DIR}/src/gui/libqgis_gui.so)
24+
SET(QGIS_CORE_LIB ${CMAKE_BINARY_DIR}/src/core/libqgis_core.so)
25+
SET(QGIS_GUI_LIB ${CMAKE_BINARY_DIR}/src/gui/libqgis_gui.so)
26+
SET(QGIS_ANALYSIS_LIB ${CMAKE_BINARY_DIR}/src/analysis/libqgis_analysis.so)
2127
ENDIF (APPLE)
2228
ENDIF (WIN32)
2329

24-
SET (BINDINGS_LIBS ${BINDINGS_CORE_LIB} ${BINDINGS_GUI_LIB})
25-
26-
SET (BINDINGS_CORE_MAKEFILE ${CMAKE_CURRENT_BINARY_DIR}/core/Makefile)
27-
SET (BINDINGS_GUI_MAKEFILE ${CMAKE_CURRENT_BINARY_DIR}/gui/Makefile)
30+
SET (BINDINGS_LIBS ${BINDINGS_CORE_LIB} ${BINDINGS_GUI_LIB} ${BINDINGS_ANALYSIS_LIB})
31+
SET (BINDINGS_CORE_MAKEFILE ${CMAKE_CURRENT_BINARY_DIR}/core/Makefile)
32+
SET (BINDINGS_GUI_MAKEFILE ${CMAKE_CURRENT_BINARY_DIR}/gui/Makefile)
33+
SET (BINDINGS_ANALYSIS_MAKEFILE ${CMAKE_CURRENT_BINARY_DIR}/analysis/Makefile)
2834

2935
# 'python' target will force to build bindings libs for core and gui
30-
ADD_CUSTOM_TARGET (python ALL DEPENDS ${BINDINGS_CORE_LIB} ${BINDINGS_GUI_LIB})
36+
ADD_CUSTOM_TARGET (python ALL DEPENDS ${BINDINGS_CORE_LIB} ${BINDINGS_GUI_LIB} ${BINDINGS_ANALYSIS_LIB})
3137

3238
# don't run python before the libs are built
33-
ADD_DEPENDENCIES (python qgis_core qgis_gui)
39+
ADD_DEPENDENCIES (python qgis_core qgis_gui qgis_analysis)
3440

35-
FILE(GLOB CORE_SIP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/core/*.sip")
36-
FILE(GLOB GUI_SIP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/gui/*.sip")
41+
FILE(GLOB CORE_SIP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/core/*.sip")
42+
FILE(GLOB GUI_SIP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/gui/*.sip")
43+
FILE(GLOB ANALYSIS_SIP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/analysis/*.sip")
3744

3845
# Step 1: during configuration
3946
# create file configure.py from configure.py.in
@@ -50,12 +57,12 @@ ENDIF (MSVC)
5057
# run python configure.py
5158
# it will run SIP utility to generate sources and will prepare makefiles
5259
# should be run everytime core or gui library has been changed
53-
ADD_CUSTOM_COMMAND(OUTPUT ${BINDINGS_CORE_MAKEFILE} ${BINDINGS_GUI_MAKEFILE} PRE_BUILD
60+
ADD_CUSTOM_COMMAND(OUTPUT ${BINDINGS_CORE_MAKEFILE} ${BINDINGS_GUI_MAKEFILE} ${BINDINGS_ANALYSIS_MAKEFILE} PRE_BUILD
5461
COMMAND ${PYTHON_EXECUTABLE}
5562
ARGS ${CMAKE_CURRENT_BINARY_DIR}/configure.py ${CMAKE_CFG_INTDIR} ${EXPORT}
56-
DEPENDS ${QGIS_CORE_LIB} ${QGIS_GUI_LIB}
63+
DEPENDS ${QGIS_CORE_LIB} ${QGIS_GUI_LIB} ${QGIS_ANALYSIS_LIB}
5764
${CMAKE_CURRENT_BINARY_DIR}/configure.py
58-
${CORE_SIP_FILES} ${GUI_SIP_FILES})
65+
${CORE_SIP_FILES} ${GUI_SIP_FILES} ${ANALYSIS_SIP_FILES})
5966

6067
# Step 3: run make in core and gui subdirs
6168
ADD_CUSTOM_COMMAND(OUTPUT ${BINDINGS_CORE_LIB} PRE_LINK
@@ -66,6 +73,10 @@ ADD_CUSTOM_COMMAND(OUTPUT ${BINDINGS_GUI_LIB} PRE_LINK
6673
COMMAND ${SIP_MAKE_PROGRAM}
6774
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gui
6875
DEPENDS ${BINDINGS_GUI_MAKEFILE})
76+
ADD_CUSTOM_COMMAND(OUTPUT ${BINDINGS_ANALYSIS_LIB} PRE_LINK
77+
COMMAND ${SIP_MAKE_PROGRAM}
78+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/analysis
79+
DEPENDS ${BINDINGS_ANALYSIS_MAKEFILE})
6980

7081
IF (BINDINGS_GLOBAL_INSTALL)
7182

python/analysis/analysis.sip

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
%Module qgis.analysis 0
3+
4+
%Import QtCore/QtCoremod.sip
5+
%Import QtGui/QtGuimod.sip
6+
%Import QtXml/QtXmlmod.sip
7+
8+
%Import core/core.sip
9+
10+
%Include qgsgeometryanalyzer.sip
11+
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/** \ingroup analysis
2+
* The QGis class provides vector geometry analysis functions
3+
*/
4+
5+
class QgsGeometryAnalyzer
6+
{
7+
%TypeHeaderCode
8+
#include <qgsgeometryanalyzer.h>
9+
%End
10+
11+
public:
12+
13+
/**
14+
* Simplify vector layer using (a modified) Douglas-Peucker algorithm
15+
* and write it to a new shape file
16+
*/
17+
bool simplify( QgsVectorLayer* layer, const QString& shapefileName, double tolerance,
18+
bool onlySelectedFeatures = false );
19+
20+
/**Calculate the true centroids, or 'center of mass' for a vector layer and
21+
write it to a new shape file
22+
*/
23+
bool centroids( QgsVectorLayer* layer, const QString& shapefileName,
24+
bool onlySelectedFeatures = false );
25+
26+
/**Create a polygon based on the extent of all (selected) features and write it to a new shape file
27+
*/
28+
bool extent( QgsVectorLayer* layer, const QString& shapefileName,
29+
bool onlySelectedFeatures = false );
30+
31+
/**Create buffers for a vector layer and write it to a new shape file
32+
*/
33+
bool buffer( QgsVectorLayer* layer, const QString& shapefileName, double bufferDistance,
34+
bool onlySelectedFeatures = false, bool dissolve = false,
35+
int bufferDistanceField = -1 );
36+
37+
/**Create convex hull(s) of a vector layer and write it to a new shape file
38+
*/
39+
bool convexHull( QgsVectorLayer* layer, const QString& shapefileName,
40+
bool onlySelectedFeatures = false,
41+
int uniqueIdField = -1 );
42+
43+
/**Dissolve a vector layer and write it to a new shape file
44+
*/
45+
bool dissolve( QgsVectorLayer* layer, const QString& shapefileName,
46+
bool onlySelectedFeatures = false,
47+
int uniqueIdField = -1 );
48+
49+
private:
50+
51+
QList<double> simpleMeasure( QgsGeometry* geometry );
52+
double perimeterMeasure( QgsGeometry* geometry, QgsDistanceArea& measure );
53+
/**Helper function to simplify an individual feature*/
54+
void simplifyFeature( QgsFeature& f, QgsVectorFileWriter* vfw, double tolerance );
55+
/**Helper function to get the cetroid of an individual feature*/
56+
void centroidFeature( QgsFeature& f, QgsVectorFileWriter* vfw );
57+
/**Helper function to buffer an individual feature*/
58+
void bufferFeature( QgsFeature& f, int nProcessedFeatures, QgsVectorFileWriter* vfw,
59+
bool dissolve, QgsGeometry** dissolveGeometry,
60+
double bufferDistance, int bufferDistanceField );
61+
/**Helper function to get the convex hull of feature(s)*/
62+
void convexFeature( QgsFeature& f, int nProcessedFeatures,
63+
QgsGeometry** dissolveGeometry );
64+
/**Helper function to dissolve feature(s)*/
65+
void dissolveFeature( QgsFeature& f, int nProcessedFeatures,
66+
QgsGeometry** dissolveGeometry );
67+
};

python/configure.py.in

+35-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ if not os.path.isdir("./core"):
3838
os.mkdir("./core")
3939
if not os.path.isdir("./gui"):
4040
os.mkdir("./gui")
41+
if not os.path.isdir("./analysis"):
42+
os.mkdir("./analysis")
4143

4244
##########################################################################
4345
# SIP -> *.CPP + *.H
@@ -46,6 +48,7 @@ if not os.path.isdir("./gui"):
4648
# system.
4749
build_file_core = build_path + "/python/core/core.sbf"
4850
build_file_gui = build_path + "/python/gui/gui.sbf"
51+
build_file_analysis = build_path + "/python/analysis/analysis.sbf"
4952

5053
# Get the SIP configuration information.
5154
config = PyQt4.pyqtconfig.Configuration()
@@ -61,6 +64,7 @@ mod_dir = os.path.join(config.default_mod_dir, "qgis")
6164
# directory where sip files will be installed
6265
sip_dir_core = os.path.join(config.default_sip_dir, "qgis/core")
6366
sip_dir_gui = os.path.join(config.default_sip_dir, "qgis/gui")
67+
sip_dir_analysis = os.path.join(config.default_sip_dir, "qgis/analysis")
6468

6569
# Run SIP to generate the code.
6670
print "Parsing SIP files for 'core' library..."
@@ -73,6 +77,11 @@ cmd = " ".join([config.sip_bin, "-c", "gui", "-b", build_file_gui, "-I", python_
7377
print cmd
7478
os.system(cmd)
7579

80+
print "Parsing SIP files for 'analysis' library..."
81+
cmd = " ".join([config.sip_bin, "-c", "analysis", "-b", build_file_analysis, "-I", python_path, "-I", config.pyqt_sip_dir, qt_sip_flags, python_path + "/analysis/analysis.sip"])
82+
print cmd
83+
os.system(cmd)
84+
7685

7786
##########################################################################
7887
# MAKEFILES
@@ -83,12 +92,13 @@ print "Creating makefiles..."
8392
# its configuration module.
8493
installs = []
8594

86-
# directories relative to core (gui) directories
95+
# directories relative to core (gui, analysis) directories
8796
installs.append([[python_path + "__init__.py", python_path + "qgisconfig.py"], mod_dir])
8897

8998

9099
installs_core = copy.copy(installs)
91100
installs_gui = copy.copy(installs)
101+
installs_analysis = copy.copy(installs)
92102

93103
# install all sip files
94104
sips_core = glob.glob(python_path + "/core/*.sip")
@@ -98,6 +108,10 @@ for sip in sips_core:
98108
sips_gui = glob.glob(python_path + "/gui/*.sip")
99109
for sip in sips_gui:
100110
installs_gui.append([os.path.basename(sip), sip_dir_gui])
111+
112+
sips_analysis = glob.glob(python_path + "/analysis/*.sip")
113+
for sip in sips_analysis:
114+
installs_analysis.append([os.path.basename(sip), sip_dir_analysis])
101115

102116

103117
# Create the Makefile. The QtModuleMakefile class provided by the
@@ -120,9 +134,18 @@ makefile_gui = sipconfig.ModuleMakefile(
120134
install_dir=mod_dir,
121135
dir="gui",
122136
universal=osx_universal)
137+
138+
makefile_analysis = sipconfig.ModuleMakefile(
139+
configuration=config,
140+
qt=qt_libs,
141+
build_file=build_file_analysis,
142+
installs=installs_analysis,
143+
install_dir=mod_dir,
144+
dir="analysis",
145+
universal=osx_universal)
123146

124-
# common settings for both core and gui libs
125-
for mk in [ makefile_core, makefile_gui ]:
147+
# common settings for core, gui and analysis libs
148+
for mk in [ makefile_core, makefile_gui, makefile_analysis ]:
126149
mk.extra_lflags.extend( "@CMAKE_MODULE_LINKER_FLAGS@".strip(' ').split(' ') )
127150
mk.extra_libs = ["qgis_core"]
128151
mk.extra_lib_dirs = [build_path+"/src/core"+intdir]
@@ -145,9 +168,18 @@ makefile_gui.extra_include_dirs.append(build_path+"/src/ui")
145168
makefile_gui.extra_include_dirs.append(src_path+"/src/plugins") # because of qgisplugin.h TODO: sort out
146169
makefile_gui.extra_cxxflags.append("-DGUI_EXPORT="+export)
147170

171+
# more settings for analysis lib
172+
makefile_analysis.extra_libs.append("qgis_analysis")
173+
makefile_analysis.extra_lib_dirs.append(build_path+"/src/analysis/vector"+intdir)
174+
makefile_analysis.extra_include_dirs.append(src_path+"/src/analysis/vector")
175+
makefile_analysis.extra_include_dirs.append(build_path+"/src/analysis/vector")
176+
makefile_analysis.extra_include_dirs.append(src_path+"/src/plugins") # because of qgisplugin.h TODO: sort out
177+
makefile_analysis.extra_cxxflags.append("-DANALYSIS_EXPORT="+export)
178+
148179
# Generate the Makefile itself.
149180
makefile_core.generate()
150181
makefile_gui.generate()
182+
makefile_analysis.generate()
151183

152184
##########################################################################
153185
# QGIS CONFIG

python/qgisconfig.py.in

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class QgisModuleMakefile(pyqtconfig.QtModuleMakefile):
3434
# Make sure our C++ library is linked.
3535
self.extra_libs.append("qgis_core")
3636
self.extra_libs.append("qgis_gui")
37+
self.extra_libs.append("qgis_analysis")
3738

3839
# Let the super-class do what it needs to.
3940
pyqtconfig.QtModuleMakefile.finalise(self)

0 commit comments

Comments
 (0)