示例#1
0
	def _SetupControls(self):
		ws = Workspace(self.dataset_)
		boundaryFeatclsLst = ws.EnumFeatureClass("*", "POLYGON")
		allFeat = [name.lower() for name in ws.EnumFeatureClass("*", "")]
		
		#初始化输入点要素与边界要素
		for boundaryFeatcls in boundaryFeatclsLst:
			self.ui_.comboBoundary.addItem(boundaryFeatcls)
			
		#设置点要素类名
		baseName = "Location"
		id = 0
		newName = "%s%d" % (baseName, id)
		while newName.lower() in allFeat:
			id += 1
			newName = "%s%d" % (baseName, id)

		self.ui_.editFeatclsName.setText(newName)
		self.ui_.editClipped.setText(newName + "_clipped")
		self.ui_.editNetwork.setText(newName + "_network")
		
		#设置布局算法名称
		layoutAlgoNames = EnumLocationBuilders()
		for layoutAlgo in layoutAlgoNames:
			self.ui_.comboShape.addItem(layoutAlgo)
			
		#设置Interval
		self.ui_.editSize.setText("80000")
		pass
示例#2
0
	def __init__(self, dataset, lingFile):
		QtCore.QObject.__init__(self)
		
		self.dlg_ = QtGui.QDialog()
		self.ui_ = Ui_Dialog()
		self.ui_.setupUi(self.dlg_)
		
		self.dataset_ = dataset
		self.ws_ = Workspace(self.dataset_)
		
		self.lingFile_ = lingFile
		
		self._SetupComboBoxes()
		self._SetupSlots()
示例#3
0
	def _OnClip(self, b):
		ws = Workspace(self.dataset_)
		
		inputFeatcls = str(self.ui_.editFeatclsName.text())
		boundaryFeatcls = str(self.ui_.comboBoundary.currentText())
		outputFeatcls = str(self.ui_.editClipped.text())
		
		if not (outputFeatcls and inputFeatcls and boundaryFeatcls):
			QtGui.QMessageBox.information(
				self.dlg_,
				"错误!".decode('cp936'),
				"输入参数中存在空项。请检查输入参数并确定。".decode('cp936')
				)
			return False
		
		if not self._AssertExist(ws, inputFeatcls): return False
		
		if outputFeatcls == inputFeatcls:
			QtGui.QMessageBox.information(
				self.dlg_,
				"错误!".decode('cp936'),
				"输出要素不可与输入要素重名。".decode('cp936')
				)
			return False
		
		if not self._WarnOverwrite(ws, outputFeatcls): return False
		
		clipFilter = ArcGISLocationClipFilter(os.path.join(self.dataset_, boundaryFeatcls))
		clipFilter.Filtrate(
			os.path.join(self.dataset_, inputFeatcls),
			os.path.join(self.dataset_, outputFeatcls)
			)
示例#4
0
	def __init__(self, ws):
		QtCore.QObject.__init__(self)
		
		self.ws_ = Workspace(ws)
		self.dlg_ = QtGui.QDialog()
		self.ui_ = Ui_Dialog()
		self.ui_.setupUi(self.dlg_)
		
		altCrtFullName = os.path.join(mainDoc.ProjDir, "AlternativeCriteriaEvaluationTable.xml")
		crtFullName = os.path.join(mainDoc.ProjDir, "Criteria.xml")
		
		self.altCrtMat_ = AltCrtMatrix()
		self.altCrtMat_.Load(altCrtFullName, crtFullName)
		
		self.SetupSlots()
		self.SetupCombo()
		pass
示例#5
0
	def _SetupComboBoxes(self):
		#设置临近算法
		algoList = EnumProximityBuilders()
		for algoName in algoList:
			self.ui_.comboProxAlgoName.addItem(algoName)
		
		#设置可做临近分析的要素类(点要素)
		ws = Workspace(self.dataset_)
		featclsNames = ws.EnumFeatureClass('*', 'POINT')
		for featclsName in featclsNames:
			self.ui_.comboLocFeatcls.addItem(featclsName)

		#设置Criteria要素类
		lt = self.lingTbl_ = LinguisticTable(self.lingFile_)
		crtNames = lt.Data().keys()
		for crtName in crtNames:
			self.ui_.comboCrtName.addItem(crtName)
示例#6
0
    def ExportToPointFeatureClass(self, ws_path):
        """
		Export Data as Point Feature Clas
		"""

        print "Begin Exporting %s ..." % self.block_desc
        ws = Workspace(ws_path)
        featcls = FeatureClass(ws.CreateFeatureClass(self.block_desc, "POINT"))
        featcls.AddField("VALUE", "FLOAT")
        featSet = featcls.Features(OpenMode.WriteOnly)

        for y in range(self.height):
            for x in range(self.width):
                pt = Point.FromXY(x, y)
                curFeat = featSet.next()
                curFeat.SetShape(pt.ArcGISPoint())
                curFeat["VALUE"] = self.data[y][x]
        featcls.Flush()
        return
示例#7
0
	def Check(self, lingTbl):
		lingVals = lingTbl.Data().values()
		vecWs = Workspace(os.path.dirname(self.inFeatcls_))
		rasWs = Workspace(os.path.dirname(os.path.dirname(self.inFeatcls_)))
		retErrors = []
		for lingVal in lingVals:
			if lingVal.FeatType == "Vector":
				if not vecWs.IsInclude(lingVal.FeatCls):
					retErrors.append("feature class \" %s \" is not exist!" % lingVal.FeatCls)
			if lingVal.FeatType == "Raster":
				if not rasWs.IsInclude(lingVal.FeatCls):
					retErrors.append("raster \" %s \" is not exist!" % lingVal.FeatCls)
		return retErrors
示例#8
0
	def _OnGenNetwork(self, b):
		ws = Workspace(self.dataset_)
		inputFeatcls = str(self.ui_.editClipped.text())
		outputFeatcls = str(self.ui_.editNetwork.text())
		dist = float(str(self.ui_.editSize.text()))
		shape = str(self.ui_.comboShape.currentText())
		
		if shape == "Eight-Neighbor-Square":
			thVal = dist * 1.5
		else:
			thVal = dist * 1.01
		
		if not (inputFeatcls and outputFeatcls):
			QtGui.QMessageBox.information(
				self.dlg_, "错误".decode('cp936'),
				"输入参数有误。请检查输入参数的正确性。".decode('cp936'))
			return False
		
		if not self._AssertExist(ws, inputFeatcls): return False
		if not self._WarnOverwrite(ws, outputFeatcls): return False
		
		adjBuilder = ArcGISPostAdjBuilder(os.path.join(self.dataset_, inputFeatcls))
		adjBuilder.Build(thVal)
		adjBuilder.Save(os.path.join(self.dataset_, outputFeatcls))
示例#9
0
class ResultImportWindow(QtCore.QObject):
	def __init__(self, ws):
		QtCore.QObject.__init__(self)
		
		self.ws_ = Workspace(ws)
		self.dlg_ = QtGui.QDialog()
		self.ui_ = Ui_Dialog()
		self.ui_.setupUi(self.dlg_)
		
		altCrtFullName = os.path.join(mainDoc.ProjDir, "AlternativeCriteriaEvaluationTable.xml")
		crtFullName = os.path.join(mainDoc.ProjDir, "Criteria.xml")
		
		self.altCrtMat_ = AltCrtMatrix()
		self.altCrtMat_.Load(altCrtFullName, crtFullName)
		
		self.SetupSlots()
		self.SetupCombo()
		pass
	
	def ShowWidget(self):
		self.dlg_.show()
	
	def ShowWidgetModal(self):
		self.dlg_.exec_()
	
	def SetupSlots(self):
		self.connect(self.ui_.btnImport, QtCore.SIGNAL("clicked(bool)"), self._OnImport)
		pass
	
	def SetupCombo(self):
		ptFeatclss = self.ws_.EnumFeatureClass("*", "POINT")
		for featcls in ptFeatclss:
			self.ui_.comboFeatcls.addItem(featcls)
		pass
	
	def _OnImport(self, b):
		featclsName = str(self.ui_.comboFeatcls.currentText())
		fullName = self.ws_.FullName(featclsName)
		#获得所有字段
		crtNames = self.altCrtMat_.CriterionNames()
		altNames = self.altCrtMat_.AlternativeNames()
		
		props = get_featureclass_properties(fullName)
		
		#添加字段
		for crtNameU in crtNames:
			crtName = str(crtNameU)
			if crtName.upper() not in props.dcFields:
				print crtName
				pGP.AddField_management(fullName, crtName, "DOUBLE")
		if "Priority".upper() not in props.dcFields:
			pGP.AddField_management(fullName, "Priority", "DOUBLE")
			
		idFieldName = props.sFID

		#写入数据
		print altNames
		rows = pGP.UpdateCursor(fullName)
		row = rows.next()
		while row:
			row_id = row.GetValue(idFieldName)
			print row_id
			altIndex = altNames.index(str(row_id))
			
			for crtNameU in crtNames:
				crtName = str(crtNameU)
				crtIndex = crtNames.index(crtName)
				val = self.altCrtMat_.AltCrtValue(altIndex, crtIndex)
				row.SetValue(crtName, val)
				
			row.SetValue("Priority", self.altCrtMat_.PriorityByIndex(altIndex))
			
			rows.UpdateRow(row)
			row = rows.next()
		pass
	
		QtGui.QMessageBox.information(
			None,
			"成功".decode('cp936'),
			"已经成功导入数据。".decode('cp936')
			)
示例#10
0
class ProximityBuilderWindow(QtCore.QObject):
	def __init__(self, dataset, lingFile):
		QtCore.QObject.__init__(self)
		
		self.dlg_ = QtGui.QDialog()
		self.ui_ = Ui_Dialog()
		self.ui_.setupUi(self.dlg_)
		
		self.dataset_ = dataset
		self.ws_ = Workspace(self.dataset_)
		
		self.lingFile_ = lingFile
		
		self._SetupComboBoxes()
		self._SetupSlots()
		
	def ShowWidget(self):
		self.dlg.show()
	
	def ShowWidgetModal(self):
		self.dlg_.exec_()
		
	def _SetupSlots(self):
		self.connect(self.ui_.btnProxAnalystAll, QtCore.SIGNAL("clicked(bool)"), self._OnProxAnalystAll)
		self.connect(self.ui_.btnCancel, QtCore.SIGNAL("clicked(bool)"), self._OnCancel)
		self.connect(self.ui_.btnAltCmp, QtCore.SIGNAL("clicked(bool)"), self._OnAltCmp)
		pass
	
	def _SetupComboBoxes(self):
		#设置临近算法
		algoList = EnumProximityBuilders()
		for algoName in algoList:
			self.ui_.comboProxAlgoName.addItem(algoName)
		
		#设置可做临近分析的要素类(点要素)
		ws = Workspace(self.dataset_)
		featclsNames = ws.EnumFeatureClass('*', 'POINT')
		for featclsName in featclsNames:
			self.ui_.comboLocFeatcls.addItem(featclsName)

		#设置Criteria要素类
		lt = self.lingTbl_ = LinguisticTable(self.lingFile_)
		crtNames = lt.Data().keys()
		for crtName in crtNames:
			self.ui_.comboCrtName.addItem(crtName)
			
	def _OnProxAnalystAll(self, b):
		#长时警告
		warnResult = QtGui.QMessageBox.warning(self.dlg_,
								  "警告".decode('cp936'),
								  "执行该命令需要较长的时间。\n执行进度可以在ArcToolBox的执行窗口中观察。是否继续?".decode('cp936'),
								  QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
								  )
		if warnResult != QtGui.QMessageBox.Yes:
			return
		
		algoName = self.ui_.comboProxAlgoName.currentText()
		ptFeatclsName = os.path.join(self.dataset_, str(self.ui_.comboLocFeatcls.currentText()))
		if algoName and ptFeatclsName:
			try:
				proxBuilder = CreateProximityBuilder(algoName, ptFeatclsName)
				errs = proxBuilder.Check(self.lingTbl_)
				if errs:
					QtGui.QMessageBox.information(
						self.dlg_,
						"错误!".decode('cp936'),
						reduce(lambda s, info: s + '\n' + str(info) ,
							   	errs)
						)
					return
				
				proxBuilder.Build(self.lingTbl_)
				proxBuilder.SaveToXMLFile(
					os.path.join(os.path.dirname(self.lingFile_), "AlternativeCriteriaEvaluationTable.xml")
					)
				
				self._SaveToFeatureClass(str(self.ui_.comboLocFeatcls.currentText()))
				
				QtGui.QMessageBox.information(
					self.dlg_,
					"成功".decode('cp936'),
					"临近分析已成功执行".decode('cp936')
					)
				
			except:
				traceback.print_exc()
				QtGui.QMessageBox.information(
					self.dlg_,
					"错误".decode('cp936'),
					"临近分析执行中出现异常。可能是由于要素不存在。".decode('cp936')
					)
	
	def _OnAltCmp(self, b):
		altCrtFileName = os.path.join(os.path.dirname(self.lingFile_), "AlternativeCriteriaEvaluationTable.xml")
		altCrtMat = AltCrtMatrix()
		altCrtMat.Load(altCrtFileName, None)
		
		crtName = str(self.ui_.comboCrtName.currentText())
		if crtName not in altCrtMat.CriterionNames():
			QtGui.QMessageBox.information(
				self.dlg_,
				"错误!".decode('cp936'),
				("Criterion " + crtName + " 对应的临近分析数据不存在!").decode('cp936')
				)
			return

		altCmpTbl = AltCmpTable.FromAltCrtTable(altCrtMat, crtName)

		altMdl = AltCmpTblModel(altCmpTbl)
		propMdl = AltCmpTblPropsModel(altCmpTbl)
		
		editor = AHPCmpTblEditor.FromModel(altMdl, None, propMdl, altCmpTbl)
		editor.dlg_.setWindowTitle('Pairwise comparison of industries w.r.t. the criterion " %s " ' % crtName )
		editor.ShowWidgetModal()
	
	def _SaveToFeatureClass(self, featclsName):
		altCrtFullName = os.path.join(mainDoc.ProjDir, "AlternativeCriteriaEvaluationTable.xml")
		
		try:
			crtFullName = os.path.join(mainDoc.ProjDir, "Criteria.xml")
		except:
			crtFullName = None
			
		altCrtMat = AltCrtMatrix()
		altCrtMat.Load(altCrtFullName, crtFullName)
		
		fullName = self.ws_.FullName(featclsName)
		
		#获得所有字段
		crtNames = altCrtMat.CriterionNames()
		altNames = altCrtMat.AlternativeNames()
		
		props = get_featureclass_properties(fullName)
		
		#添加字段	
		for crtNameU in crtNames:
			crtName = str(crtNameU)
			if crtName.upper() not in props.dcFields:
				print crtName
				pGP.AddField_management(fullName, crtName, "DOUBLE")
		if "Fuzzy_Grade".upper() not in props.dcFields:
			pGP.AddField_management(fullName, "Fuzzy_Grade", "DOUBLE")
			
		idFieldName = props.sFID

		#写入数据
		print altNames
		rows = pGP.UpdateCursor(fullName)
		row = rows.next()
		while row:
			row_id = row.GetValue(idFieldName)
			print row_id
			altIndex = altNames.index(str(row_id))
			
			for crtNameU in crtNames:
				crtName = str(crtNameU)
				crtIndex = crtNames.index(crtName)
				val = altCrtMat.AltCrtValue(altIndex, crtIndex)
				row.SetValue(crtName, val)
				
			row.SetValue("Fuzzy_Grade", altCrtMat.PriorityByIndex(altIndex))
			
			rows.UpdateRow(row)
			row = rows.next()
		pass
		
	def _OnCancel(self, b):
		self.dlg_.reject()