90 else: mesh_location=currentPath+"¥¥map¥¥100mesh¥¥map.shp" mesh_name=u"100mメッシュ" mesh_layer = QgsVectorLayer(mesh_location,mesh_name,"ogr") if mesh_layer.isValid()==False: print u"Mesh layer %s can not load" % mesh_layer.name() #select the mesh into the project # crashPath=currentPath+"¥¥crash¥¥crash.shp" crash_layer=QgsVectorLayer(crashPath,"crash","ogr") if flag==1: sql_sentence='"rwd"<=2 AND"year">=%s AND "year"<=%s'%(start,end) else: sql_sentence='"rwd">=0 AND"year">=%s AND "year"<=%s'%(start,end) crash_layer.setSubsetString(sql_sentence) #files=os.listdir(currentPath+"¥¥generate") #QgsMapLayerRegistry.instance().addMapLayer(crash_layer) #for ifile in files: # os.remove(currentPath+"¥¥generate¥¥"+ifile) QgsVectorFileWriter.writeAsVectorFormat(crash_layer,currentPath+"//generate//temp.shp","SHIFT-JIS",None,"ESRI Shapefile") select_crash_layer=QgsVectorLayer(currentPath+"//generate//temp.shp",u"抽出済交通事故","ogr") props1 = select_crash_layer.rendererV2().symbol().symbolLayer(0).properties() props1[u'outline_color']=u'0,0,0,255' props1[u'size'] = u'1.0' props1[u'color'] = u'red' Symbol1 = QgsMarkerSymbolV2.createSimple(props1) select_crash_layer.rendererV2().setSymbol(Symbol1) select_carsh_layer_id=QgsMapLayerRegistry.instance().addMapLayer(select_crash_layer) self.iface.legendInterface().setLayerVisible(select_carsh_layer_id, False) category_mesh_layer=currentPath+"//generate//category.shp" processing.runalg("qgis:countpointsinpolygon", mesh_layer, select_crash_layer, 'Count', category_mesh_layer) #using the gradual category map to classify the region,color should be Hexadecimal category_layer = QgsVectorLayer(category_mesh_layer,u"集計結果","ogr") symbols = ((u'32件以上', 32, 999999999, '#DB94F5'), (u'16~31件', 16, 31, '#FF9494'), (u'13~15件', 13, 15, '#FFDB94'), (u'10~12件', 10, 12, '#FFFF94'), (u'7~9件', 7, 9, '#B8FF94'), (u'4~6件', 4, 6, '#C4DFC4'), (u'1~3件', 1, 3, '#94E7FF'), (u'0件',0,0,'#FFFFFF')) ranges = [] for label, lower, upper, color in symbols: #set the color and outline_with by dictonary structure properties={} properties["color"]=color properties[u'outline_width'] = u'0.01' sym = QgsFillSymbolV2.createSimple(properties)
元のページ ../index.html#96