Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.09 KB | None | 0 0
  1. # Imports - some of them are nor really needed right now
  2.  
  3. import os
  4. import sys
  5. import rasterio
  6. import gdal
  7. import geopandas
  8. import numpy as np
  9. import pandas as pd
  10. import seaborn as sns
  11. import matplotlib.pyplot as plt
  12. from plotly import __version__
  13. from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
  14. import cufflinks as cf
  15. from osgeo import gdal_array
  16. # For Notebooks
  17. init_notebook_mode(connected=True)
  18. # For offline use
  19. cf.go_offline()
  20. %matplotlib inline
  21.  
  22. import pyrasterframes
  23. import pyrasterframes.rf_ipython  # enables nicer visualizations of pandas DF
  24. from pyrasterframes.rasterfunctions import (rf_geometry, rf_local_add, rf_dimensions, rf_extent, rf_crs, rf_mk_crs,
  25.                                             st_geometry, st_reproject, rf_tile)
  26. import pyspark.sql.functions as F
  27.  
  28. ########### The following commented cells are different tryouts that i made in order to read raster data locally
  29.  
  30. spark = pyrasterframes.get_spark_session()
  31.  
  32. #path = r'D:\TFM\ACF\ACF_NDVI_savgolfix.envi'
  33. #uri = 'file:///' + path.replace('\\', '/')
  34. #tryout = os.path.join("D:\\", "TFM", "ACF", "ACF_NDVI_savgolfix.envi")
  35. #uri = 'gdal:\\' + r'D:\TFM\ACF\ACF_NDVI_savgolfix'
  36. #uri = r'D:\TFM\ACF\ACF_NDVI_savgolfix.envi'
  37.  
  38.  
  39. uri = r'C:\Users\Miguel\Desktop\Teledeteccion\B02.tif'
  40. df = spark.read.raster('gdal:/'+ uri, band_indexes=range(250))
  41.  
  42.  
  43.  
  44. ### The following info might help - problem is df.count() gives 0.
  45. print(uri)
  46. # C:\Users\Miguel\Desktop\Teledeteccion\B02.tif
  47. df.count()
  48. # 0
  49. os.path.exists(uri)
  50. # True
  51. !gdalinfo {uri}
  52. '''
  53. Driver: GTiff/GeoTIFF
  54. Files: C:\Users\Miguel\Desktop\Teledeteccion\B02.tif
  55. Size is 1830, 1830
  56. Coordinate System is:
  57. PROJCS["WGS 84 / UTM zone 17N",
  58.    GEOGCS["WGS 84",
  59.        DATUM["WGS_1984",
  60.            SPHEROID["WGS 84",6378137,298.257223563,
  61.                AUTHORITY["EPSG","7030"]],
  62.            AUTHORITY["EPSG","6326"]],
  63.        PRIMEM["Greenwich",0,
  64.            AUTHORITY["EPSG","8901"]],
  65.        UNIT["degree",0.0174532925199433,
  66.            AUTHORITY["EPSG","9122"]],
  67.        AUTHORITY["EPSG","4326"]],
  68.    PROJECTION["Transverse_Mercator"],
  69.    PARAMETER["latitude_of_origin",0],
  70.    PARAMETER["central_meridian",-81],
  71.    PARAMETER["scale_factor",0.9996],
  72.    PARAMETER["false_easting",500000],
  73.    PARAMETER["false_northing",0],
  74.    UNIT["metre",1,
  75.        AUTHORITY["EPSG","9001"]],
  76.    AXIS["Easting",EAST],
  77.    AXIS["Northing",NORTH],
  78.    AUTHORITY["EPSG","32617"]]
  79. Origin = (699960.000000000000000,4300020.000000000000000)
  80. Pixel Size = (60.000000000000000,-60.000000000000000)
  81. Metadata:
  82.  AREA_OR_POINT=Area
  83. Image Structure Metadata:
  84.  COMPRESSION=DEFLATE
  85.  INTERLEAVE=BAND
  86. Corner Coordinates:
  87. Upper Left  (  699960.000, 4300020.000) ( 78d41'47.51"W, 38d49'34.61"N)
  88. Lower Left  (  699960.000, 4190220.000) ( 78d43'39.49"W, 37d50'15.04"N)
  89. Upper Right (  809760.000, 4300020.000) ( 77d26' 0.77"W, 38d47'40.30"N)
  90. Lower Right (  809760.000, 4190220.000) ( 77d28'53.90"W, 37d48'24.69"N)
  91. Center      (  754860.000, 4245120.000) ( 78d 5' 5.42"W, 38d19' 4.78"N)
  92. Band 1 Block=256x256 Type=UInt16, ColorInterp=Gray
  93. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement