Python arcpy.CheckOutExtension() Examples
The following are 7
code examples of arcpy.CheckOutExtension().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
arcpy
, or try the search function
.
Example #1
Source File: prism.py From ArcPy with GNU General Public License v2.0 | 6 votes |
def save_to_esri_grid(self, out_grid, conversion_factor=None, proj=None): import arcpy arcpy.env.overwriteOutput = True arcpy.env.workspace = os.getcwd() arcpy.CheckOutExtension('Spatial') arcpy.env.outputCoordinateSystem = prismProj if proj is not None: arcpy.env.outputCoordinateSystem = proj df = np.ma.filled(self.data, self.nodatavalue) llx = self.originX lly = self.originY - (self.nrow * -1 * self.pixelHeight) point = arcpy.Point(llx, lly) r = arcpy.NumPyArrayToRaster(df, lower_left_corner=point, x_cell_size=self.pixelWidth, y_cell_size=-1*self.pixelHeight, value_to_nodata=self.nodatavalue) if conversion_factor is not None: r *= conversion_factor r.save(out_grid)
Example #2
Source File: arcapi_test.py From arcapi with GNU Lesser General Public License v3.0 | 6 votes |
def testint_to_float(self): _dir = os.path.join(self.testingfolder, r'testing_files\rasters') ndvi = os.path.join(_dir, 'dh_july_ndvi') ob = round(arcpy.Raster(ndvi).maximum, 5) int_rst = os.path.join(_dir, 'ndvi_int') est = os.path.join(_dir, 'ndvi_tst') if arcpy.CheckExtension('Spatial') == 'Available': arcpy.CheckOutExtension('Spatial') arcpy.sa.Int(arcpy.sa.Times(ndvi, 1000000)).save(int_rst) arcpy.CheckInExtension('Spatial') ap.int_to_float(int_rst, est, 6) self.assertEqual(ob, round(arcpy.Raster(est).maximum, 5)) for rast in [int_rst, est]: try: arcpy.Delete_management(rast) except:pass pass
Example #3
Source File: arcapi_test.py From arcapi with GNU Lesser General Public License v3.0 | 6 votes |
def testfill_no_data(self): _dir = os.path.join(self.testingfolder, r'testing_files\rasters') ndvi = os.path.join(_dir, 'dh_july_ndvi') est = os.path.join(_dir, 'ndvi_fill') null = os.path.join(_dir, 'null_rst') if arcpy.CheckExtension('Spatial') == 'Available': ap.fill_no_data(ndvi, est, 10, 10) arcpy.CheckOutExtension('Spatial') arcpy.sa.IsNull(est).save(null) self.assertEqual(arcpy.Raster(null).maximum, 0) arcpy.CheckInExtension('Spatial') for rast in [est, null]: try: arcpy.Delete_management(rast) except:pass pass
Example #4
Source File: BBB_SharedFunctions.py From public-transit-tools with Apache License 2.0 | 5 votes |
def CheckOutNALicense(): if arcpy.CheckExtension("Network") == "Available": arcpy.CheckOutExtension("Network") else: arcpy.AddError("You must have a Network Analyst license to use this tool.") raise CustomError
Example #5
Source File: arcapi.py From arcapi with GNU Lesser General Public License v3.0 | 5 votes |
def int_to_float(raster, out_raster, decimals): """Convert an Integer Raster to a Float Raster *** Requires spatial analyst extension *** E.g., for a cell with a value of 45750, using this tool with 3 decimal places will give this cell a value of 45.750 Required: raster -- input integer raster out_raster -- new float raster decimals -- number of places to to move decimal for each cell Example: >>> convertIntegerToFloat(r'C:\Temp\ndvi_int', r'C:\Temp\ndvi_float', 4) """ try: import arcpy.sa as sa # check out license arcpy.CheckOutExtension('Spatial') fl_rast = sa.Float(arcpy.Raster(raster) / float(10**int(decimals))) try: fl_rast.save(out_raster) except: # having random issues with Esri GRID format, change to tiff # if grid file is created if not arcpy.Exists(out_raster): out_raster = out_raster.split('.')[0] + '.tif' fl_rast.save(out_raster) try: arcpy.CalculateStatistics_management(out_raster) arcpy.BuildPyramids_management(out_raster) except: pass msg('Created: %s' %out_raster) arcpy.CheckInExtension('Spatial') return out_raster except ImportError: return 'Module arcpy.sa not found.'
Example #6
Source File: arcapi.py From arcapi with GNU Lesser General Public License v3.0 | 5 votes |
def fill_no_data(in_raster, out_raster, w=5, h=5): """Fill "NoData" cells with mean values from focal statistics. Use a larger neighborhood for raster with large areas of no data cells. *** Requires spatial analyst extension *** Required: in_raster -- input raster out_raster -- output raster Optional: w -- search radius width for focal stats (rectangle) h -- search radius height for focal stats (rectangle) Example: >>> fill_no_data(r'C:\Temp\ndvi', r'C:\Temp\ndvi_filled', 10, 10) """ try: import arcpy.sa as sa # Make Copy of Raster _dir, name = os.path.split(arcpy.Describe(in_raster).catalogPath) temp = os.path.join(_dir, 'rast_copyxxx') if arcpy.Exists(temp): arcpy.Delete_management(temp) arcpy.CopyRaster_management(in_raster, temp) # Fill NoData arcpy.CheckOutExtension('Spatial') filled = sa.Con(sa.IsNull(temp),sa.FocalStatistics(temp,sa.NbrRectangle(w,h),'MEAN'),temp) filled.save(out_raster) arcpy.BuildPyramids_management(out_raster) arcpy.CheckInExtension('Spatial') # Delete original and replace if arcpy.Exists(temp): arcpy.Delete_management(temp) msg('Filled NoData Cells in: %s' %out_raster) return out_raster except ImportError: return 'Module arcpy.sa not found.'
Example #7
Source File: arcapi.py From arcapi with GNU Lesser General Public License v3.0 | 5 votes |
def meters_to_feet(in_dem, out_raster, factor=3.28084): """Convert DEM Z units by a factor, default factor converts m -> ft. *** Requires spatial analyst extension *** Required: in_dem -- input dem out_raster -- new raster with z values as feet factor -- number by which the input DEM is multiplied, default is 3.28084 to convert metres to feet. Example: >>> meters_to_feet(r'C:\Temp\dem_m', r'C:\Temp\dem_ft') """ try: import arcpy.sa as sa arcpy.CheckOutExtension('Spatial') out = sa.Float(sa.Times(arcpy.Raster(in_dem), factor)) try: out.save(out_raster) except: # having random issues with esri GRID format # will try to create as tiff if it fails if not arcpy.Exists(out_raster): out_raster = out_raster.split('.')[0] + '.tif' out.save(out_raster) try: arcpy.CalculateStatistics_management(out_raster) arcpy.BuildPyramids_management(out_raster) except: pass arcpy.AddMessage('Created: %s' %out_raster) arcpy.CheckInExtension('Spatial') return out_raster except ImportError: return 'Module arcpy.sa not found'