Exemple #1
0
 def load_file(self, filepath):
     try:
         if filepath.endswith((".shp", ".geojson", ".json", ".gpx")):
             loaded = pg.GeoTable(filepath)
         elif filepath.endswith(
             (".asc", ".ascii", ".tif", ".tiff", ".geotiff")):
             loaded = pg.MultiGrid(filepath)
         else:
             raise Exception()
     except:
         popup_message(self, "Unable to load file")
         return
     newlayer = LayerItem(self.layersview, data=loaded)
     newlayer.pack(fill="x")
Exemple #2
0
def runtests(filepath):

    print "------------"
    print filepath

    # basic
    t = time.time()
    geofile = pg.GeoTable(filepath)
    print "loaded", geofile
    print time.time() - t

    print "fields", geofile.fields

    t = time.time()
    print "bbox", geofile.bbox
    print time.time() - t

    t = time.time()
    geofile.create_spatial_index()
    print "spindex"
    print time.time() - t

    print len(geofile)
    print "custom"
    for feat in geofile.quick_overlap([-30 / 4, -15 / 4, 30 / 4, 15 / 4]):
        print feat.row[0], feat.bbox
    print "ne", len(list(geofile.quick_overlap([0, 0, 180, 90])))
    print "se", len(list(geofile.quick_overlap([0, -90, 180, 0])))
    print "sw", len(list(geofile.quick_overlap([-180, -90, 0, 0])))
    print "nw", len(list(geofile.quick_overlap([-180, 0, 0, 90])))

    for feat in geofile:
        print feat.id
        print feat.row
        print feat.bbox
        print "..."
        break

    geofile.save("testsave.shp")
    os.remove("testsave.shp")
    os.remove("testsave.dbf")
    os.remove("testsave.shx")
Exemple #3
0
        print "  ", type, val
resultraster.grids[0].img.convert("RGBA").save(r"C:\Users\kimo\Desktop\zonalstat.png")




### VECTOR
print ""
print "VECTOR"

# Overlay analysis

print ""
print "overlap summary"
print "polygons"
groupbydata = pg.GeoTable("test_files/shp/cshapes.shp")
valuedata = pg.GeoTable("test_files/shp/domestic.shp")
#groupbydata = pg.vector.manager.vector_clean(groupbydata)
##for feat in reversed(groupbydata):
##    if feat["CNTRY_NAME"] not in ("Saudi Arabia","Norway","Egypt","Denmark","Turkey"):
##        del groupbydata.features[feat.id]
summarized = pg.vector.analyzer.overlap_summary(groupbydata, valuedata,
                                                fieldmapping=[("inc_count","sum"),
                                                              ("Average_nk","average"),
                                                              ("Average_nw","average")] )
summarized.save("test_files/summary.shp")

##print ""
##print "intersect"
##print "polygons"
##data1 = pg.GeoTable("test_files/shp/domestic.shp")
Exemple #4
0
import pythongis as pg
import pyagg
import time

##############
# load layers
layers = pg.LayerGroup()

##data = pg.Raster(r"C:\Users\kimo\Dropbox\pygeo book 2\code\test_files\geotiff\SP27GTIF.TIF")
##data.info["nodata_value"] = 0
##lyr = pg.RasterLayer(data)
##layers.add_layer(lyr)

data = pg.GeoTable(
    r"C:\Users\kimo\Dropbox\pygeo book 2\code\test_files\shp\necountries.shp",
    encoding="latin")
#data = pg.GeoTable(r"C:\Users\kimo\Desktop\gadm2.shp", encoding="latin")
lyr = pg.VectorLayer(data,
                     fillcolor=None,
                     outlinecolor="red",
                     outlinewidth=0.2)
layers.add_layer(lyr)

#data = pg.GeoTable(r"C:\Users\kimo\Dropbox\pygeo book 2\code\test_files\gpx\track-with-extremes.gpx")
#lyr = pg.VectorLayer(data, fillcolor="white")
#layers.add_layer(lyr)

##################
# render layers in multiple independent maps
print "layers loaded, now rendering..."
t = time.clock()