当前位置: 首页>>代码示例>>Python>>正文


Python pysal.rook_from_shapefile函数代码示例

本文整理汇总了Python中pysal.rook_from_shapefile函数的典型用法代码示例。如果您正苦于以下问题:Python rook_from_shapefile函数的具体用法?Python rook_from_shapefile怎么用?Python rook_from_shapefile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rook_from_shapefile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: contiguity_from_shapefile

def contiguity_from_shapefile(shapefile, criteria='rook'):
    """
    Create a spatial weights object based on a contiguity criteria from a
    shapefile.

    Produces a "*.gal" file in the directory of the shapefile


    Argument
    --------
    shapefile: string with full path to shapefile

    criteria: string for type of contiguity ['rook'|'queen']

    Returns
    -------
    cards: nx1 numpy array with the number of neighbors for each element based
    on criterion

    """

    if criteria == 'rook':
        PS.rook_from_shapefile(shapefile)
        abb = 'r'
    else:
        PS.queen_from_shapefile(shapefile)
        abb = 'q'
    cards = NP.array(w.cardinalities.values())
    cards.shape = (len(cards),1)
    galfile = shapefile.split(".")[0] + "_" + abb + ".gal"
    gal = PS.open(galfile,'w')
    gal.write(w)
    gal.close()

    return cards
开发者ID:gelasher,项目名称:pysal-qgis,代码行数:35,代码来源:contiguity_weights.py

示例2: test_cartodb

def test_cartodb():
    import pysal
    
    # load San Francisco plots data using PySAL
    shp_path = "../test_data/sfpd_plots.shp"
    plots_shp = pysal.open(shp_path)
    plots_dbf = pysal.open(shp_path[:-3]+"dbf")     
    
    import d3viz
    d3viz.setup()    
    
    d3viz.show_map(plots_shp)
    
    shp_path = "../test_data/sf_cartheft.shp"
    crime_shp = pysal.open(shp_path)
    crime_dbf = pysal.open(shp_path[:-3]+"dbf")
    
    d3viz.show_map(crime_shp)    
    
    d3viz.quantile_map(plots_shp,'cartheft',5)
    
    user_name = 'lixun910'
    api_key = '340808e9a453af9680684a65990eb4eb706e9b56'
    
    d3viz.setup_cartodb(api_key, user_name)    
    
    plots_table = d3viz.cartodb_upload(plots_shp)
    crime_table = d3viz.cartodb_upload(crime_shp)
    print plots_table
    print crime_table    
    
    d3viz.cartodb_show_maps(plots_shp, layers=[{'shp':crime_shp}])
    
    d3viz.cartodb_show_maps(plots_shp, layers=[{'shp':crime_shp, 'css':d3viz.CARTO_CSS_POINT_CLOUD}])
    
    new_cnt_col = "mycnt"
    d3viz.cartodb_count_pts_in_polys(plots_table, crime_table, new_cnt_col)    
    
    shp_path = d3viz.cartodb_get_data(plots_table, [new_cnt_col])
    
    shp = pysal.open(shp_path)
    dbf = pysal.open(shp_path[:-3]+"dbf") 
    w = pysal.rook_from_shapefile(shp_path)    
    
    import numpy as np
    y = np.array(dbf.by_col[new_cnt_col])
    lm = pysal.Moran_Local(y, w)
    
    new_lisa_table = "cartheft_lisa" 
    new_lisa_table = d3viz.cartodb_lisa(lm, new_lisa_table)    
    
    d3viz.cartodb_show_lisa_map(shp, new_lisa_table, uuid=plots_table)
    
    d3viz.cartodb_show_lisa_map(shp, new_lisa_table, uuid=plots_table, layers=[{'shp':crime_shp, 'css':d3viz.CARTO_CSS_POINT_CLOUD}])
    
    d3viz.quantile_map(shp, new_cnt_col, 5)
    
    d3viz.quantile_map(shp, new_cnt_col, 5, basemap="leaflet_map")
    
    d3viz.close_all()
开发者ID:lixun910,项目名称:PySAL-Viz,代码行数:60,代码来源:test.py

示例3: compute

    def compute(self, vlayer, tfield, idvar,matType):
	vlayer=qgis.utils.iface.activeLayer()
	idvar=self.idVariable.currentText()
        # print type(idvar)
	tfield=self.inField.currentText()
        # print type(tfield)
	provider=vlayer.dataProvider()
	allAttrs=provider.attributeIndexes()
	caps=vlayer.dataProvider().capabilities()
	if caps & QgsVectorDataProvider.AddAttributes:
            TestField = idvar[:5]+"_qrr"
	    res = vlayer.dataProvider().addAttributes([QgsField(TestField, QVariant.Double)])
	wp=str(self.dic[str(self.inShape.currentText())])
        if matType == "Rook":
           w = py.rook_from_shapefile(wp, idVariable=unicode(idvar))
        else:
           w = py.queen_from_shapefile(wp, idVariable=unicode(idvar))

	w1=wp[:-3]+"dbf"
	db=py.open(w1)
	y=np.array(db.by_col[unicode(tfield)])
      	np.random.seed(12345)
	gc = py.Geary(y,w)
        #lm=py.Moran_Local(y,w)
	#l=lm.p_sim
	gg = gc.C
        self.SAresult.setText("The Global Geary's C index is " + str(gg))
开发者ID:gmassei,项目名称:pysal-qgis,代码行数:27,代码来源:globalGearyC.py

示例4: contiguity_from_shapefile

    def contiguity_from_shapefile(shapefile, criteria='rook'):
        print shapefile
        if criteria == 'rook':
	    PS.rook_from_shapefile(shapefile)
            abb = 'r'
    	else:
            PS.queen_from_shapefile(shapefile)
            abb = 'q'
    	    cards = NP.array(w.cardinalities.values())
    	    cards.shape = (len(cards),1)
    	    galfile = shapefile.split(".")[0] + "_" + abb + ".gal"
    	    gal = PS.open(galfile,'w')
    	    gal.write(w)
    	    gal.close()

    	return cards
开发者ID:gelasher,项目名称:pysal-qgis,代码行数:16,代码来源:weights.py

示例5: processAlgorithm

    def processAlgorithm(self, progress):
        field = self.getParameterValue(self.FIELD)
        field = field[0:10] # try to handle Shapefile field length limit
        filename = self.getParameterValue(self.INPUT)
        layer = dataobjects.getObjectFromUri(filename)
        filename = dataobjects.exportVectorLayer(layer)        
        
        contiguity = self.getParameterValue(self.CONTIGUITY)
        if contiguity == 0: # queen
            print 'INFO: Moran\'s using queen contiguity'
            w=pysal.queen_from_shapefile(filename)
        else: # 1 for rook
            print 'INFO: Moran\'s using rook contiguity'
            w=pysal.rook_from_shapefile(filename)
    
        f = pysal.open(filename.replace('.shp','.dbf'))
        y=np.array(f.by_col[str(field)])
        m = pysal.Moran(y,w,transformation = "r", permutations = 999)

        self.setOutputValue(self.I,m.I)
        
        print "Moran's I: %f" % (m.I)
        print "INFO: Moran's I values range from -1 (indicating perfect dispersion) to +1 (perfect correlation). Values close to -1/(n-1) indicate a random spatial pattern."
        print "p_norm: %f" % (m.p_norm)
        print "p_rand: %f" % (m.p_rand)
        print "p_sim: %f" % (m.p_sim)
        print "INFO: p values smaller than 0.05 indicate spatial autocorrelation that is significant at the 5% level."
        print "z_norm: %f" % (m.z_norm)
        print "z_rand: %f" % (m.z_rand)
        print "z_sim: %f" % (m.z_sim)
        print "INFO: z values greater than 1.96 or smaller than -1.96 indicate spatial autocorrelation that is significant at the 5% level."
开发者ID:weikang9009,项目名称:processing_pysal,代码行数:31,代码来源:moran.py

示例6: accept

    def accept(self):
        # look for open shapefile layers, if none 
        if len(self.comboBox.currentText()) == 0 and self.lineEdit.text() == "":
            QMessageBox.information(self, self.tr("Weights from Shapefile"), self.tr("Please select input polygon vector layer"))

        # elif self.outShape.text() == "":
        #    QMessageBox.information(self, self.tr("Sum Line Lengths In Polyons"), self.tr("Please specify output shapefile"))
        else:
            # run the PySAL logic
            if str(self.comboBox.currentText()) == "":
                shapefile = str(self.shapefile)
            else:
                shapefile = str(self.d[str(self.comboBox.currentText())])
                       
                if self.radioButton.isChecked():
                    w = PS.queen_from_shapefile(shapefile)
                    abb = 'q'
                else:
                    w = PS.rook_from_shapefile(shapefile)
                    abb = 'r'
    	        cards = NP.array(w.cardinalities.values())
    	        cards.shape = (len(cards),1)
    	        galfile = shapefile.split(".")[0] + "_" + abb + ".gal"
    	        gal = PS.open(galfile,'w')
    	        gal.write(w)
    	        gal.close()
            QDialog.accept(self)
开发者ID:gelasher,项目名称:pysal-qgis,代码行数:27,代码来源:weightsFromShapefile.py

示例7: get

 def get(self,shpName='',width=0,height=0):
     print shpName,width,height
     if not shpName in self.SHPS:
         return self.index()
     shp = pysal.open(self.SHPS[shpName])
     W = None
     if 'w' in self.request.GET:
         wtype = self.request.GET['w']
         if wtype.lower() == 'rook':
             W = pysal.rook_from_shapefile(self.SHPS[shpName])
         elif wtype.lower() == 'queen':
             W = pysal.queen_from_shapefile(self.SHPS[shpName])
         else:
             try:
                 k = int(wtype)
                 W = pysal.knnW_from_shapefile(self.SHPS[shpName],k)
             except:
                 print "No valid W"
     print shp
     if width and height:
         width=int(width)
         height=int(height)
         if W:
             return self.write({'len':len(shp), 'polygons':shift_scale_shp(shp,width,height),'width':width,'height':height,'W':W.neighbors})
         else:
             return self.write({'len':len(shp), 'polygons':shift_scale_shp(shp,width,height),'width':width,'height':height,'W':'null'})
     return self.write({'len':len(shp)})
开发者ID:GeoDaSandbox,项目名称:DynTM,代码行数:27,代码来源:views.py

示例8: test_build_lattice_shapefile

 def test_build_lattice_shapefile(self):
     of = "lattice.shp"
     pysal.build_lattice_shapefile(20, 20, of)
     w = pysal.rook_from_shapefile(of)
     self.assertEquals(w.n, 400)
     os.remove('lattice.shp')
     os.remove('lattice.shx')
开发者ID:DrizzleRisk,项目名称:Security-Project,代码行数:7,代码来源:test_user.py

示例9: test

def test():
    # Test
    shp = pysal.open(pysal.examples.get_path('NAT.shp'),'r')
    dbf = pysal.open(pysal.examples.get_path('NAT.dbf'),'r')
    
    show_map(shp)
    
    ids = get_selected(shp)
    print ids
    
    w = pysal.rook_from_shapefile(pysal.examples.get_path('NAT.shp'))
    moran_scatter_plot(shp, dbf, "HR90", w)
    
    scatter_plot(shp, ["HR90", "PS90"])
    scatter_plot_matrix(shp, ["HR90", "PS90"])
    
    quantile_map(shp, dbf, "HC60", 5, basemap="leaflet_map")
    
    
    select_ids = [i for i,v in enumerate(dbf.by_col["HC60"]) if v < 20.0]
    select(shp, ids=select_ids)
    
    
    quantile_map(shp, dbf, "HC60", 5)
    
    
    lisa_map(shp, dbf, "HC60", w)
开发者ID:sjsrey,项目名称:PySAL-Viz,代码行数:27,代码来源:d3viz.py

示例10: __init__

    def __init__(self, filepath, outname, namelist, idlist, nb="queen", factor=2):
        """
        Initiation of modules
        """
        f=Dbf(filepath+".dbf")
        #Create mapping of locations to row id
        self.locations = dict()
        i=0
        for row in f:
            uid=unicode("".join([row[k] for k in idlist]))
            locnames = unicode(", ".join([row[k] for k in namelist]),"ascii","ignore")
            self.locations[i] = {outname:locnames,"id":uid}
            i+=1
        self.__dict__[outname]= self.locations
        self.outname = outname
        #Get Neightbor weights by queen, rook, knn, distance
        if nb=="queen":
            self.wt = pysal.queen_from_shapefile(filepath+".shp")
        elif nb=="rook":
            self.wt = pysal.rook_from_shapefile(filepath+".shp")
        elif nb=="knn":
            self.wt = pysal.knnW_from_shapefile(filepath+".shp", k=factor)
        elif nb=="distance":
            self.wt = pysal.threshold_binaryW_from_shapefile(filepath+".shp",k)

        #Create dictionary of neighbors for each region
        self.neighbors ={}
        for i,j in enumerate(self.wt):
            self.neighbors[self.locations[i]["id"]] = {self.outname:self.locations[i][self.outname]
                            ,"neighbors":dict([[self.locations[k]["id"],self.locations[k][self.outname]] for k in j.keys()])}
开发者ID:pyrrhus429,项目名称:geo,代码行数:30,代码来源:spatialareas.py

示例11: read_files

def read_files(filepath, **kwargs):
    """
    Reads a dbf/shapefile pair, squashing geometries into a "geometry" column.
    """
    #keyword arguments wrapper will strip all around dbf2df's required arguments
    geomcol = kwargs.pop('geomcol', 'geometry')
    weights = kwargs.pop('weights', '')
    
    dbf_path, shp_path = _pairpath(filepath)

    df = dbf2df(dbf_path, **kwargs)
    df[geomcol] = shp2series(shp_path)

    if weights != '' and isinstance(weights, str):
        if weights.lower() in ['rook', 'queen']:
            if weights.lower() == 'rook':
                df.W = ps.rook_from_shapefile(shp_path)
            else:
                df.W = ps.queen_from_shapefile(shp_path)
        else:
            try:
                W_path = os.path.splitext(dbf_path)[0] + '.' + weights
                df.W = ps.open(W_path).read()
            except IOError:
                print('Weights construction failed! Passing on weights')
    
    return df
开发者ID:CartoDB,项目名称:pysal,代码行数:27,代码来源:file_utilities.py

示例12: get_weight_matrix

    def get_weight_matrix(self, array, rook=False, shpfile=None):
        """Return the spatial weight matrix based on pysal functionalities

        Keyword arguments:
            array    Numpy array with inventory values.
            rook    Boolean to select spatial weights matrix as rook or
                    queen case.
            shpfile    Name of file used to setup weight matrix.
        """
        # Get case name.
        if rook:
            case = 'rook'
        else:
            case = 'queen'
        # Get grid dimension.
        dim = array.shape
        if self.sptype == 'vector':
            try:
                # Create weights based on shapefile topology using defined key.
                if shpfile is None:
                    shpfile = self.invfile
                # Differentiat between rook and queen's case.
                if rook:
                    w = pysal.rook_from_shapefile(shpfile, self.invcol)
                else:
                    w = pysal.queen_from_shapefile(shpfile, self.invcol)
            except:
                msg = "Couldn't build spatial weight matrix for vector "
                "inventory <%s>" % (self.name)
                raise RuntimeError(msg)

            # Match weight index to inventory array index.
            w.id_order = list(self.inv_index)

            logger.info("Weight matrix in %s's case successfully calculated "
                        "for vector dataset" % case)
        elif self.sptype == 'raster':
            try:
                # Construct weight matrix in input grid size.
                w = pysal.lat2W(*dim, rook=rook)
            except:
                msg = "Couldn't build spatial weight matrix for raster "
                "inventory <%s>" % (self.name)
                raise RuntimeError(msg)

            logger.info("Weight matrix in %s's case successfully calculated "
                        "for raster dataset" % case)

        # Print imported raster summary.
        print("[ WEIGHT NUMBER ] = ", w.n)
        print("[ MIN NEIGHBOR ] = ", w.min_neighbors)
        print("[ MAX NEIGHBOR ] = ", w.max_neighbors)
        print("[ ISLANDS ] = ", *w.islands)
        print("[ HISTOGRAM ] = ", *w.histogram)

        self._Inventory__modmtime()

        return(w)
开发者ID:m4sth0,项目名称:sauventory,代码行数:58,代码来源:spatialinventory.py

示例13: setUp

 def setUp(self):
     db=pysal.open(pysal.examples.get_path("columbus.dbf"),"r")
     y = np.array(db.by_col("HOVAL"))
     self.y = np.reshape(y, (49,1))
     X = []
     X.append(db.by_col("INC"))
     self.X = np.array(X).T
     self.w = pysal.rook_from_shapefile(pysal.examples.get_path("columbus.shp"))
     self.w.transform = 'r'
开发者ID:CartoDB,项目名称:pysal,代码行数:9,代码来源:test_error_sp_hom.py

示例14: test_DistanceBand_ints

 def test_DistanceBand_ints(self):
     """ see issue #126 """
     w = pysal.rook_from_shapefile(
         pysal.examples.get_path("lattice10x10.shp"))
     polygons = pysal.open(
         pysal.examples.get_path("lattice10x10.shp"), "r").read()
     points2 = [tuple(map(int, poly.vertices[0])) for poly in polygons]
     w2 = pysal.DistanceBand(points2, 1)
     for k in range(w.n):
         self.assertEqual(w[k], w2[k])
开发者ID:Alwnikrotikz,项目名称:pysal,代码行数:10,代码来源:test_Distance.py

示例15: setUp

    def setUp(self):
        from pysal import rook_from_shapefile
        self.w = rook_from_shapefile(pysal.examples.get_path('10740.shp'))

        self.neighbors = {0: [3, 1], 1: [0, 4, 2], 2: [1, 5], 3: [0, 6, 4], 4: [1, 3,
                                                                                7, 5], 5: [2, 4, 8], 6: [3, 7], 7: [4, 6, 8], 8: [5, 7]}
        self.weights = {0: [1, 1], 1: [1, 1, 1], 2: [1, 1], 3: [1, 1, 1], 4: [1, 1,
                                                                              1, 1], 5: [1, 1, 1], 6: [1, 1], 7: [1, 1, 1], 8: [1, 1]}

        self.w3x3 = pysal.lat2W(3, 3)
开发者ID:cheneason,项目名称:pysal,代码行数:10,代码来源:test_weights.py


注:本文中的pysal.rook_from_shapefile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。