def pointDensityGridCreation(self, store, gridType, distancegrid, addEmptyGrids, projection, envelope, filterExpression, geomFieldName): #features = store.features() newSchema = gvsig.createFeatureType() newSchema.append("ID", "INTEGER", 10) newSchema.append("COUNT", "INTEGER", 20) newSchema.append("TOTAL", "INTEGER", 20) #newSchema.append("VALUE", "DOUBLE", 20) newSchema.append("PERC", "DOUBLE", 5) newSchema.append("GEOMETRY", "GEOMETRY") newSchema.get("GEOMETRY").setGeometryType(geom.POLYGON, geom.D2) ### Capa 2: Aprovechando las opciones de la Toolbox output_store = self.buildOutPutStore( newSchema, SHAPE_TYPE_POLYGON, "DensityGrid", "RESULT_POLYGON" ) #pdb.set_trace() n = 0 if gridType==GRID_HEXAGON_HORIZONTAL: rotate = False pointDensityGrid_hexa(self, distancegrid, store, output_store, rotate, addEmptyGrids, projection, envelope, filterExpression, geomFieldName) elif gridType==GRID_HEXAGON_VERTICAL: rotate = True pointDensityGrid_hexa(self, distancegrid, store, output_store, rotate, addEmptyGrids, projection, envelope, filterExpression, geomFieldName) elif gridType==GRID_SQUARE: #pointDensityGrid_square(distancegrid,distancegrid,store) pointDensityGrid_square(self, distancegrid, store, output_store, addEmptyGrids, projection, envelope, filterExpression, geomFieldName) output_store.finishEditing()
def getPointsFeatureType(self): schema = createFeatureType() schema.append("POB_ID", "INTEGER", 10) schema.append("CENTRO_ID", "INTEGER", 10) schema.append("GEOMETRY", "GEOMETRY") schema.get("GEOMETRY").setGeometryType(POINT, D2) return schema
def getPolygonFeatureType(self): schema = createFeatureType() schema.append("ID", "INTEGER", 10) schema.append("COUNT", "INTEGER", 10) schema.append("NAME", "STRING", 50) schema.append("GEOMETRY", "GEOMETRY") schema.get("GEOMETRY").setGeometryType(POLYGON, D2) return schema
def updateCalculatedField(self, columnSelectedDescriptor, store, exp): i18nManager = ToolsLocator.getI18nManager() try: self.taskStatus.setRangeOfValues(0, 1) self.taskStatus.setCurValue(0) self.taskStatus.add() #Process newComputed = DALLocator.getDataManager( ).createFeatureAttributeEmulatorExpression( store.getDefaultFeatureType(), exp) #Check if required field is himself for req in newComputed.getRequiredFieldNames(): if req == columnSelectedDescriptor.getName(): mss = i18nManager.getTranslation( "_A_computed_field_can_not_have_itself_as_required_field_in_the_expression" ) self.taskStatus.message(mss) logger(mss, LOGGER_WARN) raise Throwable(mss) newFeatureType = gvsig.createFeatureType( store.getDefaultFeatureType()) #DefaultEditableFeatureAttributeDescriptor efd = newFeatureType.getEditableAttributeDescriptor( columnSelectedDescriptor.getName()) efd.setFeatureAttributeEmulator(newComputed) try: store.edit() store.update(newFeatureType) store.commit() self.taskStatus.incrementCurrentValue() self.taskStatus.message( i18nManager.getTranslation("_Computed_field_updated")) except: #store.cancelEditing() self.taskStatus.message( i18nManager.getTranslation( "_Computed_field_calculation_has_some_errors")) logger( "Not able change Emulatore Expression Attribute in Feature Type", LOGGER_ERROR) except: pass finally: if self.editingMode: try: store.edit() except: logger("Not able to put store into editing mode", LOGGER_ERROR)
def main(*args): proportionX = 1 proportionY = 1 xi = 0 yi = 0 baseLines = createBaseLayers(proportionX, proportionY) # Setting coordinates to aoristic clock nameFieldHour = "HORA" nameFieldDay = "DIA" patternHour = '%H:%M:%S' patternDay = '%Y-%m-%d' layer = gvsig.currentLayer() # New points layer schema = gvsig.createFeatureType( layer.getFeatureStore().getDefaultFeatureType()) # DefaultFeatureType newPoints = gvsig.createShape(schema) # Transform set = layer.getFeatureStore().getFeatureSet() newPoints.edit() store = newPoints.getFeatureStore() for f in set: fieldHour = f.get(nameFieldHour) d = datetime.datetime.strptime(fieldHour, patternHour).time() totalSecs = float(d.minute * 60 + d.second) / 3600 x = float(d.hour) + float(totalSecs) x = x * proportionX fieldDay = f.get(nameFieldDay) dday = datetime.datetime.strptime(fieldDay, patternDay) y = dday.weekday() y = y * proportionY nf = store.createNewFeature(f) newGeom = geom.createPoint(geom.D2, x, y) nf.setDefaultGeometry(newGeom) store.insert(nf) newPoints.commit() gvsig.currentView().addLayer(newPoints) mp = MapContextLocator.getMapContextManager() leg = mp.createLegend("HeatmapLegend") leg.setROI(baseLines.getFullEnvelope().getGeometry()) leg.setUseFixedViz(False) leg.setCorrectionFixedViz(100) leg.setDistance(30) colorTables = SymbologySwingLocator.getSwingManager().createColorTables( ).get(5) leg.setColorTable(colorTables.getColors()) newPoints.setLegend(leg)
def process(selfStatus,store,raster,outputFilePath=None): # SELECT METHOD TO TRANSFORM POINTS method = "setZFromRaster" #None geomManager = GeometryLocator.getGeometryManager() if store.getFeatureSelection().getSize()>0: fset = store.getFeatureSelection() else: fset = store.getFeatureSet() nsch = gvsig.createFeatureType(store.getDefaultFeatureType()) if method == "setZFromRaster": transformMethod = setZFromRaster subtype = geom.D3M nsch.get("GEOMETRY").setGeometryType(nsch.get("GEOMETRY").getGeometryType(), subtype) if outputFilePath is None: outputFilePath = gvsig.getTempFile("result_geometries",".shp") ns = gvsig.createShape(nsch,outputFilePath) ns.edit() store = ns.getFeatureStore() selfStatus.setRangeOfValues(0,fset.getSize()) for f in fset: selfStatus.next() fg = f.getDefaultGeometry() #print "Default geometry: ", fg, if subtype == None: subtype = fg.getGeometryType().getSubType() nm = geomManager.create(fg.getGeometryType().getType(), subtype) if isinstance(fg,MultiPrimitive): # for multiprimitive for i in range(0,fg.getPrimitivesNumber()): iPol = fg.getPrimitiveAt(i) np = geomManager.create(iPol.getGeometryType().getType(), subtype) insertVertexFromGeometryInGeometry(iPol, np, raster, transformMethod) ## INSERT nm.addPrimitive(np) else: # for primitive insertVertexFromGeometryInGeometry(fg, nm, raster, transformMethod) ## INSERT nf = store.createNewFeature(f) nf.set("GEOMETRY", nm) store.insert(nf) if selfStatus.isCanceled() == True: ns.finishEditing() return True ns.finishEditing() gvsig.currentView().addLayer(ns)
def process(selfStatus, store, cutDistance, outputFilePath=None): geomManager = GeometryLocator.getGeometryManager() fset = store.getFeatureSet() nsch = gvsig.createFeatureType(store.getDefaultFeatureType()) if outputFilePath is None: outputFilePath = gvsig.getTempFile("result_geometries", ".shp") ns = gvsig.createShape(nsch, outputFilePath) ns.edit() store = ns.getFeatureStore() #selfStatus.setRangeOfValues(0,fset.getSize()) for f in fset: #selfStatus.next() fg = f.getDefaultGeometry() if isinstance(fg, MultiPrimitive): linesToProcess = [] for i in range(0, fg.getPrimitivesNumber()): iLine = fg.getPrimitiveAt(i) linesToProcess.append(iLine) else: linesToProcess = [fg] for iLine in linesToProcess: setLines = processLine3D(iLine, cutDistance) for singleLine in setLines: #if singleLine.getNumVertices()<=1: # continue nf = store.createNewFeature(f) nf.set("GEOMETRY", singleLine) store.insert(nf) #if selfStatus.isCanceled() == True: # ns.finishEditing() # return True ns.finishEditing() gvsig.currentView().addLayer(ns) return ns
def createGroupyByFeatureType(store): ft = store.getDefaultFeatureType() newft = gvsig.createFeatureType(ft) for attr in ft.getAttributeDescriptors(): dataTypeName = attr.getDataTypeName() name = attr.getName() size = attr.getSize() + 5 if dataTypeName == "String": pass elif dataTypeName == "Double" or dataTypeName == "Long": appendNumericField(name, "Double", size, newft) elif dataTypeName == "Integer": appendNumericField(name, dataTypeName, size, newft) elif dataTypeName == "Date": pass elif dataTypeName == "GEOMETRY": pass else: print "Not supported: ", dataTypeName print dataTypeName name = attr.getName() typefield = attr.getType() return newft
def process(self,flayer, field1,field2,changeDefaultValue,defaultValue,changeForValue): i18nManager = ToolsLocator.getI18nManager() fstore = flayer.getFeatureStore() fset = fstore.getFeatureSet()#lection() featureType = gvsig.createFeatureType(fstore.getDefaultFeatureType()) nameField1 = featureType.get(field1).getName() nameField2 = featureType.get(field2).getName() fields = [field1, field2] allFields = [attr.getName() for attr in featureType.getAttributeDescriptors()] n=0 while True: n += 1 if len(nameField1)>=10: newFieldName1 = nameField1[:-1]+str(n) else: newFieldName1 = nameField1+str(n) if newFieldName1 not in allFields: break if self.isCanceled(): return False n=0 while True: n += 1 if len(nameField2)>=10: newFieldName2 = nameField2[:-1]+str(n) else: newFieldName2 = nameField2+str(n) if newFieldName2 not in allFields and newFieldName1 != newFieldName2: break if self.isCanceled(): return False featureType.add(newFieldName1,DataTypes.DATE) featureType.add(newFieldName2,DataTypes.DATE) if self.isCanceled(): return False if self.isPolygon(flayer.getFeatureStore()): output_store = self.buildOutPutStore( featureType, SHAPE_TYPE_POLYGON, "Result_polygon", "RESULT_POLYGON" ) self.buildOutPutStore( featureType, SHAPE_TYPE_LINE, "Result_line", "RESULT_LINE" ) self.buildOutPutStore( featureType, SHAPE_TYPE_POINT, "Result_point", "RESULT_POINT" ) elif self.isLine(flayer.getFeatureStore()): output_store = self.buildOutPutStore( featureType, SHAPE_TYPE_LINE, "Result_line", "RESULT_LINE" ) self.buildOutPutStore( featureType, SHAPE_TYPE_POLYGON, "Result_polygon", "RESULT_POLYGON" ) self.buildOutPutStore( featureType, SHAPE_TYPE_POINT, "Result_point", "RESULT_POINT" ) elif self.isPoint(flayer.getFeatureStore()): output_store = self.buildOutPutStore( featureType, SHAPE_TYPE_POINT, "Result_point", "RESULT_POINT" ) self.buildOutPutStore( featureType, SHAPE_TYPE_POLYGON, "Result_polygon", "RESULT_POLYGON" ) self.buildOutPutStore( featureType, SHAPE_TYPE_LINE, "Result_line", "RESULT_LINE" ) else: raise ("Not valid value") dataManager = ApplicationLocator.getManager().getDataTypesManager() self.setRangeOfValues(0, fset.getSize()) self.getStatus().setTitle("Processing..") self.setProgressText(i18nManager.getTranslation("_Converting_fields_to_dates")) for f in fset: nf =output_store.createNewFeature(f) ## Value 1 value1 = f.get(field1) if changeDefaultValue is True and str(value1)==str(defaultValue): value1 = changeForValue nf.set(newFieldName1, intToDate(value1)) ## Value 2 value2 = f.get(field2) if changeDefaultValue is True and str(value2)==str(defaultValue): value2 = changeForValue nf.set(newFieldName2, intToDate(value2)) output_store.insert(nf) if self.isCanceled() is True: return False else: self.next() output_store.finishEditing() #m = MapContextLocator.getMapContextManager().createLayer("Result", output_store) #gvsig.currentView().addLayer(m) #if not self.isPolygon(flayer.getFeatureStore()): # self.getNewVectorLayer("RESULT_POLYGON","result_polygon",OutputVectorLayer.SHAPE_TYPE_POLYGON,[Integer.getClass(0)],[""]) #elif not self.isLine(flayer.getFeatureStore()): # self.getNewVectorLayer("RESULT_LINE","result_line",OutputVectorLayer.SHAPE_TYPE_LINE,[Integer.getClass(0)],[""]) #elif not self.isPoint(flayer.getFeatureStore()): # self.getNewVectorLayer("RESULT_POINT","result_point",OutputVectorLayer.SHAPE_TYPE_POINT,[Integer.getClass(0)],[""]) return True
def createRingMap(store, table, idStore, idTable, fields, default_segs, gaps, half_step, internalRadius, radiusInterval, centerTopSector, labelOnlyFirstSector, labelIdSector, createSectorLabel): # Pre vars ring_num = len(fields) # number fileds if store.getFeatureSelection().getSize() > 0: featureSet = store.getSelection() else: featureSet = store.getFeatureSet() feature_count = featureSet.getSize() featureList = [] envelopeSelection = GeometryLocator.getGeometryManager().createEnvelope(D2) for feature in featureSet: featureList.append(feature.getReference()) envelopeSelection.add(feature.getDefaultGeometry().getEnvelope()) # Prepare radius from envelope envelope = envelopeSelection #store.getEnvelope() centroid = envelope.getGeometry().centroid() if centroid.isValid() == False and featureSet.getSize() == 1: centroid = featureList[0].getFeature().getDefaultGeometry( ).getInteriorPoint() if internalRadius > 0: radius = internalRadius else: radius = getRadiusFromEnvelope(envelope) if radius == 0: # radius can be 0 from extent of a single point radius = getRadiusFromEnvelope(store.getEnvelope()) # Prepare radiusInterval if radiusInterval > 0: radius_interval = radiusInterval else: radius_interval = radius / ring_num # Prepare schema newSchema = gvsig.createFeatureType() newSchema.append("LABEL", "STRING", 20) newSchema.append("VALUE", "DOUBLE", 20, 5) newSchema.append("NUMSECTOR", "INTEGER", 10) newSchema.append("NUMRING", "INTEGER", 10) newSchema.append("ROTATION", "DOUBLE", 10, 5) newSchema.append("GEOMETRY", "GEOMETRY") newSchema.get("GEOMETRY").setGeometryType(POLYGON, D2) ringShape = gvsig.createShape(newSchema) # Line shape lineSchema = gvsig.createFeatureType(table.getDefaultFeatureType()) rm = lineSchema.getEditableAttributeDescriptor("GEOMETRY") if rm != None: lineSchema.remove(rm) lineSchema.append("GEOMETRY", "GEOMETRY") lineSchema.get("GEOMETRY").setGeometryType(LINE, D2) lineShape = gvsig.createShape(lineSchema) lineShape.edit() # Point-label shape pointSchema = gvsig.createFeatureType( ringShape.getFeatureStore().getDefaultFeatureType()) pointSchema.append("STRVALUE", "STRING", 20) pointSchema.get("GEOMETRY").setGeometryType(POINT, D2) pointShape = gvsig.createShape(pointSchema) pointStore = pointShape.getFeatureStore() pointShape.edit() # Vars ringStore = ringShape.getFeatureStore() ringShape.edit() step_angle = 360.0 / feature_count if centerTopSector: half_step = half_step + (step_angle / 2) #-((default_segs*gaps)/2) idx_side = 0 correction_from_deg = (((step_angle / default_segs) * gaps) / 2) correction_to_deg = (((step_angle / default_segs) * gaps) / 2) for i in xrange(0, feature_count): from_deg = half_step - (idx_side * step_angle) - correction_from_deg to_deg = half_step - ((idx_side + 1) * step_angle) + correction_to_deg # Get closest rin = radius + (radius_interval * (1)) rout = radius prering = create_ring_cell(centroid, from_deg, to_deg, rin, rout, default_segs).centroid() feature = getClosest(featureList, prering) builder = store.createExpressionBuilder() for iring in xrange(0, len(fields)): #featureIdValues = table.findFirst(str(idTable)+"="+str(feature.get(idStore))) # QUERY ## Eq expression expFilter = builder.eq(builder.column(idTable), builder.constant( feature.get(idStore))).toString() #exp = ExpressionEvaluatorLocator.getManager().createExpression() #exp.setPhrase(expFilter) #evaluator = DALLocator.getDataManager().createExpresion(exp) #featureIdValues = table.findFirst(evaluator) featureIdValues = table.findFirst(expFilter) #fq1 = store.createFeatureQuery() #fq1.setFilter(evaluator) #fq1.retrievesAllAttributes() new = ringStore.createNewFeature() rin = radius + (radius_interval * (iring + 1)) rout = radius + (radius_interval * iring) ring = create_ring_cell(centroid, from_deg, to_deg, rin, rout, default_segs) new.set("LABEL", fields[iring]) new.set("VALUE", feature.get(fields[iring])) rotation = ((from_deg + to_deg) / 2) - 90 if -90 < rotation < -240: rotation += 180 new.set("ROTATION", rotation) new.set("NUMSECTOR", i) new.set("NUMRING", iring) new.set("GEOMETRY", ring) ringStore.insert(new) if iring == 0: featureGeometryCentroid = getInsidePoint( feature.getDefaultGeometry(), ring) centroidRing = getRingCentroid(ring, centroid, radius, radius_interval, from_deg, to_deg, 4) line = createLine(D2, [centroidRing, featureGeometryCentroid]) newFeatureLine = lineShape.getFeatureStore().createNewFeature( featureIdValues) newFeatureLine.set("GEOMETRY", line) lineShape.getFeatureStore().insert(newFeatureLine) if labelIdSector == True: pointLocation = getRingCentroid(ring, centroid, rout, radius_interval, from_deg, to_deg, 2) newFeaturePoint = pointStore.createNewFeature() newFeaturePoint.set("LABEL", fields[iring]) newFeaturePoint.set("VALUE", feature.get(fields[iring])) newFeaturePoint.set("STRVALUE", str(feature.get(fields[iring]))) newFeaturePoint.set("ROTATION", rotation) newFeaturePoint.set("NUMSECTOR", i) newFeaturePoint.set("NUMRING", iring) newFeaturePoint.set("GEOMETRY", pointLocation) pointStore.insert(newFeaturePoint) if createSectorLabel == True: # iLabel==True and pointLocation = getRingCentroid(ring, centroid, rout + radius_interval, radius_interval, from_deg, to_deg, 5) newFeaturePoint = pointStore.createNewFeature() newFeaturePoint.set("LABEL", feature.get(idTable)) newFeaturePoint.set("VALUE", 0) newFeaturePoint.set("STRVALUE", str(feature.get(idTable))) newFeaturePoint.set("ROTATION", ((from_deg + to_deg) / 2) - 90) newFeaturePoint.set("NUMSECTOR", i) newFeaturePoint.set("NUMRING", len(fields) + 1) newFeaturePoint.set("GEOMETRY", pointLocation) pointStore.insert(newFeaturePoint) if labelOnlyFirstSector: labelIdSector = False idx_side += 1 lineShape.commit() pointShape.commit() ringShape.commit() pointShape.setName("PointLabel") lineShape.setName("LineRing") ringShape.setName("RingMap") try: vil = VectorialIntervalLegend(POLYGON) vil.setStartColor(Color.white) vil.setEndColor(Color.red) vil.setIntervalType(1) ii = vil.calculateIntervals(ringShape.getFeatureStore(), "VALUE", 8, POLYGON) vil.setIntervals(ii) vil.setClassifyingFieldTypes([7]) ringShape.setLegend(vil) except: pass gvsig.currentView().addLayer(ringShape) leg = SingleSymbolLegend() leg.setShapeType(LINE) manager = leg.getSymbolManager() newline = manager.createSymbol(LINE) newline.setColor(Color.black) leg.setDefaultSymbol(newline) lineShape.setLegend(leg) gvsig.currentView().addLayer(lineShape) leg = SingleSymbolLegend() leg.setShapeType(POINT) manager = leg.getSymbolManager() pointSymbol = manager.createSymbol(POINT) pointSymbol.setColor(Color.black) leg.setDefaultSymbol(pointSymbol) pointSymbol.setSize(0) pointShape.setLegend(leg) ds = LabelingFactory().createDefaultStrategy(pointShape) ds.setTextField("LABEL") ds.setRotationField("ROTATION") ds.setFixedSize(20) pointShape.setLabelingStrategy(ds) pointShape.setIsLabeled(True) gvsig.currentView().addLayer(pointShape)
def processAlgorithm(self): i18nManager = ToolsLocator.getI18nManager() params = self.getParameters() table = params.getParameterValueAsTable( "inputTable") #gvsig.currentTable() field = params.getParameterValueAsInt( "tableField") #str(commonsdialog.inputbox("Name of the field")) limitNumberOfKeys = 10 store = None try: #import pdb #pdb.set_trace() features = table.getBaseDataObject().getFeatureStore( ).getFeatureSet() except: commonsdialog.msgbox("Table not opened") return False count = dict() size = features.getSize() self.setRangeOfValues(0, size) #self.getStatus().setTitle("Processing..") self.setProgressText(i18nManager.getTranslation("_Counting_features")) n = 0 numberOfKeys = 0 changedToDB = False for f in features: n += 1 ff = str(f.get(field)) if ff in count.keys(): count[ff] += 1 else: count[ff] = 1 numberOfKeys += 1 # Check if is necessary change to a disk db for keys if changedToDB is False and numberOfKeys > limitNumberOfKeys: changedToDB = True store, temp = createDiskDataBase() for k in count.keys(): temp[k] = count[k] count = temp store.commit() # Save db each 50000 values if n % 50000 == 0 and changedToDB is True: store.commit() # Each 100000 values make a commit if db is being used if self.isCanceled() is True: return False else: self.next() if changedToDB is True and store != None: store.commit() sch = gvsig.createFeatureType() sch.append('ID', 'STRING', 15) sch.append('COUNT', 'INTEGER', 20) dbf = gvsig.createDBF(sch, gvsig.getTempFile("count", ".dbf")) dbf.edit() for k, v in count.iteritems(): f = dbf.createNewFeature() f.set('ID', k) f.set('COUNT', v) dbf.insert(f) dbf.commit() if changedToDB is True and store != None: store.close() d = gvsig.loadDBF(dbf.getFullName()) d.setName(i18nManager.getTranslation("_Count_Duplicates_Table")) return True
def createRingMap( store, table, idStore, idTable, fields, default_segs, gaps, half_step, internalRadius, radiusInterval, centerTopSector): # Pre vars ring_num = len(fields) # number fileds if store.getFeatureSelection().getSize()>0: featureSet = store.getSelection() else: featureSet = store.getFeatureSet() feature_count = featureSet.getSize() featureList = [] envelopeSelection = GeometryLocator.getGeometryManager().createEnvelope(D2) for feature in featureSet: featureList.append(feature.getReference()) envelopeSelection.add(feature.getDefaultGeometry().getEnvelope()) # Prepare envelope envelope = envelopeSelection #store.getEnvelope() centroid = envelope.getGeometry().centroid() if internalRadius > 0: radius = internalRadius else: minx = envelope.getLowerCorner().getX() miny = envelope.getLowerCorner().getY() maxx = envelope.getUpperCorner().getX() maxy = envelope.getUpperCorner().getY() radius = (((maxx - minx)**2 + (maxy - miny)**2) **0.5) / 2.0 if radiusInterval > 0: radius_interval = radiusInterval else: radius_interval = radius / ring_num # Prepare schema newSchema = gvsig.createFeatureType() #table.getDefaultFeatureType()) #rm = newSchema.getEditableAttributeDescriptor("GEOMETRY") #if rm!=None: # newSchema.remove(rm) #newSchema.append("GEOMETRY", "GEOMETRY") newSchema.append("LABEL", "STRING", 20) newSchema.append("VALUE", "DOUBLE", 20,5) newSchema.append("NUMSECTOR", "INTEGER", 10) newSchema.append("NUMRING", "INTEGER", 10) newSchema.append("ROTATION", "DOUBLE", 10,5) newSchema.append("GEOMETRY", "GEOMETRY") newSchema.get("GEOMETRY").setGeometryType(POLYGON, D2) ringShape = gvsig.createShape(newSchema) # Line shape lineSchema = gvsig.createFeatureType(table.getDefaultFeatureType()) rm = lineSchema.getEditableAttributeDescriptor("GEOMETRY") if rm!=None: lineSchema.remove(rm) lineSchema.append("GEOMETRY", "GEOMETRY") lineSchema.get("GEOMETRY").setGeometryType(LINE, D2) lineShape = gvsig.createShape(lineSchema) lineShape.edit() # Vars ringStore = ringShape.getFeatureStore() ringShape.edit() iLabel = True step_angle = 360.0 / feature_count if centerTopSector: half_step = half_step + (step_angle/2)-((default_segs*gaps)/2) #step_angle / 2.0 idx_side = 0 for i in xrange(0, feature_count): from_deg = half_step - (idx_side * step_angle) to_deg = half_step - ((idx_side + 1) * step_angle) to_deg = to_deg - (default_segs* gaps) print from_deg, to_deg # Get closest rin = radius+(radius_interval*(1)) rout = radius prering = create_ring_cell(centroid, from_deg, to_deg, rin, rout, default_segs, gaps).centroid() feature = getClosest(featureList, prering) if iLabel == True: pass for iring in xrange(0, len(fields)): featureIdValues = table.findFirst(idTable+"="+feature.get(idStore)) new = ringStore.createNewFeature() rin = radius+(radius_interval*(iring+1)) rout = radius+(radius_interval*iring) ring = create_ring_cell(centroid, from_deg, to_deg, rin, rout, default_segs, gaps) new.set("LABEL", fields[iring]) new.set("VALUE", feature.get(fields[iring])) new.set("ROTATION", ((from_deg + to_deg) / 2)-90) new.set("NUMSECTOR", i) new.set("NUMRING", iring) new.set("GEOMETRY", ring) ringStore.insert(new) if iring==0: featureGeometryCentroid = getInsidePoint(feature.getDefaultGeometry(), ring) centroidRing = getRingCentroid(ring,centroid, radius,radius_interval, from_deg, to_deg,default_segs, gaps) line = createLine(D2, [centroidRing,centroid]) #featureGeometryCentroid]) newFeatureLine = lineShape.getFeatureStore().createNewFeature(featureIdValues) newFeatureLine.set("GEOMETRY", line) lineShape.getFeatureStore().insert(newFeatureLine) iLabel = False idx_side +=1 lineShape.commit() ringShape.commit() lineShape.setName("LineRing") ringShape.setName("RingMap") vil = VectorialIntervalLegend(POLYGON) vil.setStartColor(Color.red) vil.setEndColor(Color.blue) vil.setIntervalType(1) ii = vil.calculateIntervals(ringShape.getFeatureStore(), "VALUE", 5, POLYGON) vil.setIntervals(ii) ringShape.setLegend(vil) gvsig.currentView().addLayer(ringShape) leg = SingleSymbolLegend() leg.setShapeType(LINE) manager = leg.getSymbolManager() newline = manager.createSymbol(LINE) newline.setColor(Color.black) leg.setDefaultSymbol(newline) lineShape.setLegend(leg) gvsig.currentView().addLayer(lineShape)
def aoristicClock(store, nameFieldHour, nameFieldDay, rangeHoursParameter, rangeDaysParameter, expression, xi=0, yi=0, proportion=1, selfStatus=None): i18nManager = ToolsLocator.getI18nManager() centroid = geom.createPoint(geom.D2, xi, yi) if rangeHoursParameter == "": rangeHoursParameter = "0-23" if rangeDaysParameter == "": rangeDaysParameter = "0-6" try: rangeHours = processRangeHoursParameter(rangeHoursParameter) except: rangeHours = processRangeHoursParameter("0-23") try: rangeDays = processRangeDaysParameter(rangeDaysParameter) except: rangeDays = processRangeDaysParameter("0-6") days = len(rangeDays) hours = len(rangeHours) internalRadius = 1*proportion half_step = 90 default_segs = 15 separationGaps = 1 centerTopSector = False radiusInterval = 1*proportion iLabel = True createSectorLabel=True labelOnlyFirstSector = True dayOrderRange = [ Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY, Calendar.SUNDAY ] dayNames = {Calendar.MONDAY:i18nManager.getTranslation("_Monday"), Calendar.TUESDAY:i18nManager.getTranslation("_Tuesday"), Calendar.WEDNESDAY:i18nManager.getTranslation("_Wednesday"), Calendar.THURSDAY:i18nManager.getTranslation("_Thursday"), Calendar.FRIDAY:i18nManager.getTranslation("_Friday"), Calendar.SATURDAY:i18nManager.getTranslation("_Saturday"), Calendar.SUNDAY:i18nManager.getTranslation("_Sunday") } # Prepare schema newSchema = gvsig.createFeatureType() newSchema.append("LABEL", "STRING", 20) newSchema.append("VALUE", "DOUBLE", 20,5) newSchema.append("DAY", "INTEGER", 10) newSchema.append("HOUR", "INTEGER", 10) newSchema.append("ROTATION", "DOUBLE", 10,5) newSchema.append("GEOMETRY", "GEOMETRY") newSchema.get("GEOMETRY").setGeometryType(POLYGON, D2) ringShape = gvsig.createShape(newSchema) # Point-label shape pointSchema = gvsig.createFeatureType(ringShape.getFeatureStore().getDefaultFeatureType()) pointSchema.append("STRVALUE", "STRING", 20) pointSchema.get("GEOMETRY").setGeometryType(POINT, D2) pointShape = gvsig.createShape(pointSchema) pointStore=pointShape.getFeatureStore() pointShape.edit() # Vars ringStore = ringShape.getFeatureStore() ringShape.edit() ring_num = days step_angle = 360.0 / hours if centerTopSector: half_step = half_step + (step_angle/2) #-((default_segs*gaps)/2) idx_side = 0 if internalRadius > 0: radius = internalRadius # Prepare radiusInterval if radiusInterval > 0: radius_interval = radiusInterval else: radius_interval = (radius / ring_num)*proportion last = None gaps = 0 if selfStatus!=None: selfStatus.setRangeOfValues(0,len(rangeHours)) processText = i18nManager.getTranslation("_Processing") for position in range(0, len(rangeHours)): #xrange(0, hours): if selfStatus!=None: selfStatus.setProgressText(processText + ": " + str(position)+" / "+str(int(len(rangeHours)))) if selfStatus.isCanceled() == True: ringShape.finishEditing() return True i = rangeHours[position] if len(rangeHours)==(position+1): rangePosition = 0 else: rangePosition = position+1 if i != (rangeHours[rangePosition]-1): if i==23 and rangeHours[rangePosition]==0: gaps = 0 else: gaps=separationGaps else: gaps=0 correction_from_deg = (((step_angle/default_segs)*0)/2) correction_to_deg = (((step_angle/default_segs)*gaps)/2) from_deg = half_step - (idx_side * step_angle) - correction_from_deg to_deg = half_step - ((idx_side + 1) * step_angle) + correction_to_deg rin = (radius+(radius_interval*(1)))*proportion rout = radius*proportion rin, rout prering = create_ring_cell(centroid, from_deg, to_deg, rin, rout, default_segs).centroid() for iring, day in enumerate(rangeDays, 1): #range(0, dayOrderRange) #day = rangeDays[iring] new = ringStore.createNewFeature() rin = radius+(radius_interval*(iring+1)) rout = radius+(radius_interval*iring) ring = create_ring_cell(centroid, from_deg, to_deg, rin, rout, default_segs) #new.set("LABEL", fields[iring]) #new.set("VALUE", feature.get(fields[iring])) #rotation = ((from_deg + to_deg) / 2)-90 rotation = from_deg - 90 if -90 < rotation < -240: rotation+=180 new.set("ROTATION", rotation) new.set("HOUR", i) new.set("DAY", day) new.set("GEOMETRY", ring) ringStore.insert(new) if iLabel==True and labelOnlyFirstSector==True: pointLocation = getRingInitVertex(ring,centroid, rout,radius_interval, from_deg, proportion) newFeaturePoint = pointStore.createNewFeature() newFeaturePoint.set("LABEL", day) #newFeaturePoint.set("VALUE", feature.get(fields[iring])) newFeaturePoint.set("STRVALUE", dayNames[day]) newFeaturePoint.set("ROTATION", rotation) newFeaturePoint.set("HOUR", i) newFeaturePoint.set("DAY", day) newFeaturePoint.set("GEOMETRY", pointLocation) pointStore.insert(newFeaturePoint) if createSectorLabel==True: pointLocation = getRingInitVertex(ring,centroid, rout+radius_interval,radius_interval, from_deg, proportion) newFeaturePoint = pointStore.createNewFeature() newFeaturePoint.set("LABEL", i) newFeaturePoint.set("VALUE", 0) newFeaturePoint.set("STRVALUE", " "+str(i)+":00") newFeaturePoint.set("ROTATION", from_deg -90) newFeaturePoint.set("HOUR", i) #newFeaturePoint.set("DAY", iring) newFeaturePoint.set("GEOMETRY", pointLocation) pointStore.insert(newFeaturePoint) #if gaps>0: #create anotation end of gaps time # pointLocation = getRingInitVertex(ring,centroid, rout+radius_interval,radius_interval, to_deg+(1.5*correction_to_deg), 1) # newFeaturePoint = pointStore.createNewFeature() # newFeaturePoint.set("LABEL", i) # newFeaturePoint.set("VALUE", 0) # newFeaturePoint.set("STRVALUE", " "+str(i+1)+":00") # newFeaturePoint.set("ROTATION", (to_deg+(1.5*correction_to_deg))-90) # newFeaturePoint.set("HOUR", i) # #newFeaturePoint.set("DAY", iring) # newFeaturePoint.set("GEOMETRY", pointLocation) # pointStore.insert(newFeaturePoint) if labelOnlyFirstSector: labelOnlyFirstSector = False idx_side += 1 ringShape.commit() ### ### GET VALUES ### if store.getSelection().getSize()!=0: fset = store.getSelection() elif (expression!=None and not expression.isEmpty()): #.getPhrase() != '': evaluator = DALLocator.getDataManager().createExpresion(expression) #evaluator = expressionEvaluatorManager.createEvaluator(expression) fq = store.createFeatureQuery() fq.addFilter(evaluator) fq.retrievesAllAttributes() fset = store.getFeatureSet(fq) else: fset = store.getFeatureSet() ### ### INIT DICT ### dictValues = {} for d in dayOrderRange: dictHour={} for h in range(0,24): dictHour[h] = 0 dictValues[d] = dictHour ### ### FILL DICT ### for f in fset: dateFieldHour = f.get(nameFieldHour) #getFieldAsDate(f.get(nameFieldHour), patternHour) dateFieldDay = f.get(nameFieldDay) #getFieldAsDate(f.get(nameFieldDay), patternDay) if isinstance(dateFieldDay, Date) and isinstance(dateFieldHour, Date): cal = Calendar.getInstance() cal.setTime(dateFieldDay) day = cal.get(Calendar.DAY_OF_WEEK) cal = Calendar.getInstance() cal.setTime(dateFieldHour) hour = cal.get(Calendar.HOUR_OF_DAY) dictValues[day][hour] += 1 ### ### FILL SHAPE WITH VALUES ### ringShape.edit() store = ringShape.getFeatureStore() fset = store.getFeatureSet() for f in fset: e = f.getEditable() h = f.get("HOUR") d = f.get("DAY") e.set("VALUE", dictValues[d][h]) fset.update(e) ### ### FINISH ### ringShape.commit() ringShape.setName("Ao-Clock") pointShape.commit() pointShape.setName("Ao-Label") gvsig.currentView().addLayer(ringShape) gvsig.currentView().addLayer(pointShape) ### ### LEGEND AND LABELS ### try: vil = VectorialIntervalLegend(POLYGON) vil.setStartColor(Color.green) vil.setEndColor(Color.red) vil.setIntervalType(1) ii = vil.calculateIntervals(ringShape.getFeatureStore(), "VALUE", 5, POLYGON) vil.setIntervals(ii) vil.setClassifyingFieldTypes([7]) ringShape.setLegend(vil) except: pass ds = LabelingFactory().createDefaultStrategy(pointShape) ds.setTextField("STRVALUE") ds.setRotationField("ROTATION") ds.setFixedSize(20) pointShape.setLabelingStrategy(ds) pointShape.setIsLabeled(True) leg = SingleSymbolLegend() leg.setShapeType(geom.POINT) manager = leg.getSymbolManager() pointSymbol = manager.createSymbol(geom.POINT) pointSymbol.setColor(Color.black) pointSymbol.setSize(0) leg.setDefaultSymbol(pointSymbol) pointShape.setLegend(leg) return True
def main(*args): import gvsig ft = gvsig.createFeatureType() add_import_attr_ARENA2_ACCIDENTES(ft) print ft
def createLayerFilterByArea(sourceLayer): sourceSchema = sourceLayer.getSchema() targetSchema = gvsig.createFeatureType(sourceSchema) targetLayer = gvsig.createShape(targetSchema, prefixname="new_layer") return targetLayer
def createBaseLayers(proportionX=1, proportionY=1): schema = gvsig.createFeatureType() # DefaultFeatureType schema.append("GEOMETRY", "GEOMETRY") schema.get("GEOMETRY").setGeometryType(geom.LINE, geom.D2) baseLines = gvsig.createShape(schema) schema = gvsig.createFeatureType() # DefaultFeatureType schema.append("LABEL", "STRING", 20) schema.append("GEOMETRY", "GEOMETRY") schema.get("GEOMETRY").setGeometryType(geom.POINT, geom.D2) basePoints = gvsig.createShape(schema) days = { 0: "Monday", 1: "Tuesday", 2: "Wednesday", 3: "Thursday", 4: "Friday", 5: "Saturday", 6: "Sunday" } # Y axis: Days numberDays = 7 numberHours = 24 for k in range(0, numberHours + 1): line = geom.createGeometry(geom.LINE) for i in range(0, numberDays): x = proportionX * k y = proportionY * i point = geom.createPoint(geom.D2, x, y) line.addVertex(point) if i == numberDays - 1: x = x y = y + 0.2 point = geom.createPoint(geom.D2, x, y) basePoints.append({"LABEL": k, "GEOMETRY": point}) baseLines.append({"GEOMETRY": line}) # X axis: Days numberDays = 7 numberHours = 24 for i in range(0, numberDays): line = geom.createGeometry(geom.LINE) x = 0 y = proportionY * i point = geom.createPoint(geom.D2, x, y) line.addVertex(point) x = proportionX * numberHours point = geom.createPoint(geom.D2, x, y) line.addVertex(point) baseLines.append({"GEOMETRY": line}) x = -2.5 y = y - 0.2 point = geom.createPoint(geom.D2, x, y) basePoints.append({"LABEL": days[i], "GEOMETRY": point}) # Commits basePoints.commit() baseLines.commit() # Labels and legends ds = LabelingFactory().createDefaultStrategy(basePoints) ds.setTextField("LABEL") ds.setFixedSize(20) basePoints.setLabelingStrategy(ds) basePoints.setIsLabeled(True) leg = SingleSymbolLegend() leg.setShapeType(geom.POINT) manager = leg.getSymbolManager() pointSymbol = manager.createSymbol(geom.POINT) pointSymbol.setColor(Color.black) pointSymbol.setSize(0) leg.setDefaultSymbol(pointSymbol) basePoints.setLegend(leg) leg = SingleSymbolLegend() leg.setShapeType(geom.LINE) manager = leg.getSymbolManager() newline = manager.createSymbol(geom.LINE) newline.setColor(Color.black) leg.setDefaultSymbol(newline) baseLines.setLegend(leg) gvsig.currentView().addLayer(basePoints) gvsig.currentView().addLayer(baseLines) return baseLines
def aoristicClockGrid(store, proportionX, proportionY, nameFieldHour, nameFieldDay, expression, xi=0, yi=0, selfStatus=None): # Setting coordinates to aoristic clock #layer = gvsig.currentLayer() # New points layer schema = gvsig.createFeatureType(store.getDefaultFeatureType()) # DefaultFeatureType newPoints = gvsig.createShape(schema) ## ## TRANSFROM TO DATE COORDINATES FOR GRID ## #if store.getSelection().getSize()==0: # fs = store.getFeatureSet(fq) #else: # fs = store.getSelection() ### ### GET VALUES ### if store.getSelection().getSize()!=0: fset = store.getSelection() elif (expression!=None and not expression.isEmpty()): evaluator = DALLocator.getDataManager().createExpresion(expression) #evaluator = expressionEvaluatorManager.createEvaluator(expression) fq = store.createFeatureQuery() fq.addFilter(evaluator) fq.retrievesAllAttributes() fset = store.getFeatureSet(fq) else: fset = store.getFeatureSet() newStore = newPoints.getFeatureStore() newStore.edit(FeatureStore.MODE_APPEND) size = fset.getSize() if selfStatus!=None: selfStatus.setRangeOfValues(0,size) n = 0 i18nManager = ToolsLocator.getI18nManager() processText = i18nManager.getTranslation("_Processing") for f in fset: n+=1 if selfStatus!=None: selfStatus.next() selfStatus.setProgressText(processText + ": " + str(n)+" / "+str(int(size))) if selfStatus.isCanceled() == True: newPoints.finishEditing() return True dateFieldHour = f.get(nameFieldHour) #getFieldAsDate(f.get(nameFieldHour), patternHour) dateFieldDay = f.get(nameFieldDay) #getFieldAsDate(f.get(nameFieldDay), patternDay) newDateGeom = getGeometryFromDayHour(dateFieldDay, dateFieldHour,proportionX, proportionY) nf = newStore.createNewFeature(f) nf.setDefaultGeometry(newDateGeom) newStore.insert(nf) newStore.commit() gvsig.currentView().addLayer(newPoints) baseLines = createBaseLayers(proportionX, proportionY) ### ### LEGEND AND LABELS ### mp = MapContextLocator.getMapContextManager() try: leg = mp.createLegend("HeatmapLegend") leg.setROI(baseLines.getFullEnvelope().getGeometry()) #leg.setUseFixedViz(False) #leg.setCorrectionFixedViz(100) leg.setDistance(30) try: colorTables = SymbologySwingLocator.getSwingManager().createColorTables() colorTable = colorTables.get(0) leg.setColorTable(colorTable.getColors()) except: leg.setColorTable(100, Color(0, 0, 255, 0), Color(255, 0, 0, 255)) newPoints.setLegend(leg) except: ex = sys.exc_info()[1] error = "Error" + str(ex.__class__.__name__)+ str(ex) logger(error, LOGGER_ERROR) newPoints.setName("Ao-Data")
def convert2shp(data, outf): featureType = createFeatureType() featureType.append("ID_ALE", "INTEGER") featureType.append("ID_EXP", "INTEGER") featureType.append("EXP_COD", "STRING", 25) featureType.append("TEX_NIF", "STRING", 25) featureType.append("ID_CROQUIS", "INTEGER") featureType.append("PROV", "INTEGER") featureType.append("MUN_CAT", "INTEGER") featureType.append("AGREGADO", "INTEGER") featureType.append("ZONA", "INTEGER") featureType.append("POLIGONO", "INTEGER") featureType.append("PARCELA", "INTEGER") featureType.append("RECINTO", "INTEGER") featureType.append("COD_TIP_AL", "STRING", 25) featureType.append("USO", "STRING", 100) featureType.append("SUPERF_DEC", "DOUBLE") featureType.append("COEF_REG", "DOUBLE") featureType.append("SECANO_REG", "DOUBLE") featureType.append("ELEGIBILID", "DOUBLE") featureType.append("FC_ALMENDR", "DOUBLE") featureType.append("FC_ALGARRO", "DOUBLE") featureType.append("FC_AVELLAN", "DOUBLE") featureType.append("FC_NOGALES", "DOUBLE") featureType.append("FC_PISTACH", "DOUBLE") featureType.append("DN_SURFACE", "DOUBLE") featureType.append("FC_TOTAL", "DOUBLE") featureType.append("GEOMETRY", "GEOMETRY").setGeometryType(POLYGON, D2) shape = createShape(featureType, outf) store = shape.getDataStore() store.edit() #FeatureStore.MODE_APPEND) for linea in data["DECLARACION"]["LINEA_DECLARACION"]: feature = store.createNewFeature() feature.set("ID_ALE", null2zero(linea.get("ID_ALE", None))) feature.set("ID_EXP", null2zero(linea.get("ID_EXP", None))) feature.set("EXP_COD", null2empty(linea.get("EXP_COD", None))) feature.set("TEX_NIF", null2empty(linea.get("TEX_NIF", None))) feature.set("ID_CROQUIS", null2zero(linea.get("ID_CROQUIS", None))) feature.set("PROV", null2zero(linea.get("PROV", None))) feature.set("MUN_CAT", null2zero(linea.get("MUN_CAT", None))) feature.set("AGREGADO", null2zero(linea.get("AGREGADO", None))) feature.set("ZONA", null2zero(linea.get("ZONA", None))) feature.set("POLIGONO", null2zero(linea.get("POLIGONO", None))) feature.set("PARCELA", null2zero(linea.get("PARCELA", None))) feature.set("RECINTO", null2zero(linea.get("RECINTO", None))) feature.set("COD_TIP_AL", null2empty(linea.get("COD_TIPO_ALE", None))) feature.set("USO", null2empty(linea.get("USO", None))) feature.set("SUPERF_DEC", null2zero(linea.get("SUPERFICIE_DECLARADA", None))) feature.set("COEF_REG", null2zero(linea.get("COEF_REG", None))) feature.set("SECANO_REG", null2zero(linea.get("SECANO_REGADIO", None))) feature.set("ELEGIBILID", null2zero(linea.get("ELEGIBILIDAD", None))) feature.set("FC_ALMENDR", null2zero(linea.get("FC_ALMENDROS", None))) feature.set("FC_ALGARRO", null2zero(linea.get("FC_ALGARROBOS", None))) feature.set("FC_AVELLAN", null2zero(linea.get("FC_AVELLANOS", None))) feature.set("FC_NOGALES", null2zero(linea.get("FC_NOGALES", None))) feature.set("FC_PISTACH", null2zero(linea.get("FC_PISTACHOS", None))) feature.set("FC_TOTAL", null2zero(linea.get("FC_TOTAL", None))) feature.set("DN_SURFACE", null2zero(linea.get("DN_SURFACE", None))) feature.set("GEOMETRY", linea.get("WKT", None)) store.insert(feature) store.finishEditing()
def processImportFields(tableTarget, fieldTarget, tableSource, fieldSource, data, translator, taskStatus=None): ### Init processimportfields" # Update ft #translator = NamesTranslator.createTrimTranslator(11) storeTarget = tableTarget.getFeatureStore() storeSource = tableSource.getFeatureStore() ftTarget = storeTarget.getDefaultFeatureType() ftSource = storeSource.getDefaultFeatureType() #Names translator init #for attr in ftTarget: # translator.addSource(attr.getName()) # if storeTarget == storeSource: logger("Can't use same store for import tables", LOGGER_ERROR) return # Checks ## Ningun del nombre de los campos nuevos usados existe ya en la tabla previa for d in data: used = ftTarget.getAttributeDescriptor(d['idname']) if used != None: logger("Field " + d['idname'] + " already created in table", LOGGER_ERROR) return # Process newftTarget = gvsig.createFeatureType(ftTarget) newftSource = gvsig.createFeatureType(ftSource) for d in data: name = d["idfield"] descriptor = newftSource.getEditableAttributeDescriptor(name) newname = d["idname"] descriptor.setName(newname) newftTarget.addLike(descriptor) try: storeTarget.edit() storeTarget.update(newftTarget) storeTarget.commit() except: logger("Not able to update feature type", LOGGER_ERROR) return # Update values storeTarget.edit() fsetSource = tableSource.getFeatureStore().getFeatureSet() if taskStatus != None: taskStatus.setRangeOfValues(0, fsetSource.getSize()) taskStatus.setCurValue(0) taskStatus.add() for fSource in fsetSource: if taskStatus != None and taskStatus.isCancellationRequested(): break if taskStatus != None: taskStatus.incrementCurrentValue() # QUERY builder = storeTarget.createExpressionBuilder() ## Eq expression expFilter = builder.eq(builder.column(fieldTarget), builder.constant( fSource.get(fieldSource))).toString() exp = ExpressionEvaluatorLocator.getManager().createExpression() exp.setPhrase(expFilter) evaluator = DALLocator.getDataManager().createExpresion(exp) #filterValue = str(field2)+"="+str(fTarget.get(fieldTarget)) fqTarget = storeTarget.createFeatureQuery() fqTarget.setFilter(evaluator) #for d in data: #need al attributos to get editable valid # if not ftSource.getAttributeDescriptor(d["idfield"]).isReadOnly(): # fq1.addAttributeName(d["idname"]) #defaultGeometry = ftTarget.getDefaultGeometryAttributeName() #fqTarget.addAttributeName(defaultGeometry) fqTarget.retrievesAllAttributes() # UPDATE VALUES fsetTarget = storeTarget.getFeatureSet(fqTarget) for ftTarget in fsetTarget: efTarget = ftTarget.getEditable() for d in data: if newftTarget.getAttributeDescriptor( d["idname"]).isReadOnly(): #logger("Field is read only", LOGGER_WARN) continue value = fSource.get(d["idfield"]) efTarget.set(d["idname"], value) fsetTarget.update(efTarget) if storeTarget.canCommitChanges( ) and storeTarget.getPendingChangesCount() > 100000: storeTarget.commitChanges() storeTarget.commit() try: pass except: ex = sys.exc_info()[1] logger("Not able to update features value: " + str(ex), LOGGER_ERROR) try: DisposeUtils.disposeQuietly(fsetTarget) DisposeUtils.disposeQuietly(fsetSource) store1.cancelEditing() except: logger("Not able to cancel editing", LOGGER_ERROR) finally: DisposeUtils.disposeQuietly(fsetTarget) DisposeUtils.disposeQuietly(fsetSource)