POST
|
This does the job. Thanks depth_new = np.roll(depth, 720, axis = 3)
... View more
07-03-2018
03:20 AM
|
0
|
0
|
998
|
POST
|
Hi, I've been several days with this not quite getting what I need. Any help would be much appreciated. I'm trying to use python to shift the longitude values of a netcdf file. The original file longitude goes from -1.875 to +360 I need the file to show properly when importing it in Arcmap (Make NetCDF Raster Layer) so the raster and its values are -180 180 (as well as -90 90). The values are vertical velocity depth. I'm trying a short script that someone showed online with a similar issue. Apparently it worked for him. In my case I just manage to shift the frame but not the values (see picture). Any suggestions? Many thanks import arcpy
import numpy as np
import netCDF4
from netCDF4 import Dataset
from arcpy import env
arcpy.env.overwriteOutput=True
from arcpy.sa import*
arcpy.CheckOutExtension("Spatial")
Bathy = Dataset(r"H:\NETcdf_TEST\tdhteo.pfclapr.nc",'r+', format="NETCDF4")
lon = Bathy.variables[u'longitude'][:]
lat = Bathy.variables[u'latitude'][:]
depth = Bathy.variables[u'W_mm_dpth'][:]
depth_new = np.roll(depth, 360, axis = 1)
lon_new = lon[:]-178.125
Bathy.variables[u'longitude'][:] = lon_new
Bathy.variables[u'W_mm_dpth'][:] = depth_new
Bathy.close()
... View more
07-02-2018
06:31 AM
|
0
|
1
|
1382
|
POST
|
Just to add: The script works with the FCs in Geographic Coordinates (degrees) using the global extent (below) I would expect the same in Mollweide Projected (meters) especially as you are measuring distances... arcpy.env.extent = arcpy.Extent(-180.0, -90.0, 180.0, 90.0)
env.workspace = r"H:\OUTPUT.gdb"
fcdist = arcpy.ListFeatureClasses("")
for fc in fcdist:
output = EucDistance(fc, 5, 0.5, "")
output.save(env.workspace + "\\" + fc + "_250km")
... View more
06-25-2018
06:52 AM
|
0
|
0
|
1413
|
POST
|
To be more precise when using the tool in ArcMap session: It works when I use the "same as layer..." (in this case I use a Bathymetry raster layer) in the Processing Extent option within Environment Settings. If I use " As specified Below" option and I enter the extent manually it does not work. I don't quite get it to be honest
... View more
06-25-2018
06:21 AM
|
0
|
0
|
1413
|
POST
|
As I previously mentioned, no problem at all when using the tool in ArcMap and setting the global Extent
... View more
06-25-2018
05:39 AM
|
0
|
1
|
1413
|
POST
|
Thanks Dan. The Euclidean Distance calculation is the end part of a larger script. In the previous step I do project the FCs to Mollweide. It is just when using the Extent that does not work but I guess it may still be related with the problem? # reproject to Mollweide and create 250km buffer
fcprj = arcpy.ListFeatureClasses()
for fc in fcprj:
mollweide = arcpy.SpatialReference("Mollweide (world)")
arcpy.BatchProject_management(fc, OUTworkspace, mollweide, "", "")
fcdist = arcpy.ListFeatureClasses("*1")
for fc in fcdist:
output = EucDistance(fc, 250000, 10000, "")
output.save(OUTworkspace + "\\" + fc + "_250km")
... View more
06-25-2018
05:37 AM
|
0
|
0
|
1413
|
POST
|
Projected Coordinate System: World_Mollweide Projection: Mollweide False_Easting: 0.00000000 False_Northing: 0.00000000 Central_Meridian: 0.00000000 Linear Unit: Meter Geographic Coordinate System: GCS_WGS_1984 Datum: D_WGS_1984 Prime Meridian: Greenwich Angular Unit: Degree
... View more
06-25-2018
05:24 AM
|
0
|
1
|
1413
|
POST
|
Hi, I need to calculate some Euclidean Distances out of a list of FCs in a GDB. I notice that when using an extent (in this case a global extent - see script) it does not work. It does work without specifying an extent but I do need to use one otherwise the resulting raster is a bit cut out at the edges. When using the tool in ArcMap and specifying the extent in the Environments it does work. Any help/suggestions will be greatly appreciated. import arcpy
from arcpy import env
arcpy.env.overwriteOutput=True
from arcpy.sa import*
arcpy.CheckOutExtension("Spatial")
arcpy.env.extent = arcpy.Extent(-180.0, -90.0, 180.0, 90.0)
env.workspace = r"H:\OUTPUT.gdb"
fcdist = arcpy.ListFeatureClasses("")
for fc in fcdist:
output = EucDistance(fc, 250000, 10000, "")
output.save(env.workspace + "\\" + fc + "_250km")
... View more
06-25-2018
05:11 AM
|
0
|
9
|
1651
|
POST
|
Hi again, Thanks to everyone that have had a look into this. I guess it is a tricky one. Just to add on my question/query: I have a macro written in VB by someone at the company quite a while ago that does what I intend to do (improve) in Python. I have no knowledge of VB so not really sure how to translate this into Python. I assume that if this can be done in VB it should also by possible in Python? Please see the VB code below and if you can help with this it would be greatly appreciated. Const STYLE_FIELD = "CSID"
Const LABEL_FIELD = "Description"
' --------------------------------------------
Public Sub LabelStylesFromAnotherField()
Dim pMxDoc As IMxDocument
Dim pGeoFtrLyr As IGeoFeatureLayer
Dim pLegInfo As ILegendInfo
Dim pLegGrp As ILegendGroup
Dim pLegCls As ILegendClass
Dim f As Long
Set pMxDoc = ThisDocument
Set pGeoFtrLyr = pMxDoc.FocusMap.Layer(0)
Set pLegInfo = pGeoFtrLyr.Renderer
Set pLegGrp = pLegInfo.LegendGroup(0)
For f = 0 To pLegGrp.ClassCount - 1
Set pLegCls = pLegGrp.Class(f)
pLegCls.Label = GetStyleLabel(pLegCls.Label, STYLE_FIELD, LABEL_FIELD, pGeoFtrLyr)
Next f
pMxDoc.UpdateContents
MsgBox "Updated Symbol Labels", vbInformation, ""
End Sub
Private Function GetStyleLabel(sStyle As String, sStyleField As String, sLabelField As String, pGeoFtrLyr As IGeoFeatureLayer) As String
Dim pFtrCls As IFeatureClass
Dim lStyFldIdx As Long
Dim lLblFldIdx As Long
Dim lID As Long
Dim pQryFltr As IQueryFilter
Set pFtrCls = pGeoFtrLyr.DisplayFeatureClass
lStyFldIdx = pFtrCls.FindField(sStyleField)
lLblFldIdx = pFtrCls.FindField(sLabelField)
If lStyFldIdx = -1 Or lLblFldIdx = -1 Then
GetStyleLabel = sStyle
Exit Function
End If
Set pQryFltr = New QueryFilter
pQryFltr.WhereClause = sStyleField + " = '" + sStyle + "'"
lID = pFtrCls.Select(pQryFltr, esriSelectionTypeIDSet, esriSelectionOptionOnlyOne, Nothing).IDs.Next
If lID = -1 Then
GetStyleLabel = sStyle
Exit Function
End If
GetStyleLabel = CStr(pFtrCls.GetFeature(lID).Value(lLblFldIdx))
End Function
... View more
05-16-2018
03:38 AM
|
0
|
0
|
465
|
POST
|
Hi there I've spent quite a while searching online and ArcGIS/ArcPy Help for a solution with no success, so I wonder if someone could think of a way around this issue: I would like to change the symbology Value Field of a Feature Class within an MXD. I need first to set the symbology of the FC to "Match to symbols in a style" using a Value Field and then use Python to change the Value Field keeping the same symbology style. I know that ArcGIS does not support "Match to symbols in a style" symbology Type but I wonder if there is away around this. It would be something like the script below but replacing the symbology Type with "something else". Hope I explained the issue clearly. Many thanks. import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
lyrlist = arcpy.mapping.ListLayers(mxd)
for lyr in lyrlist:
if lyr.symbologyType == "UNIQUE_VALUES":
lyr.symbology.valueField = "DESCRIPTION"
lyr.symbology.addAllValues()
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
del mxd
... View more
05-15-2018
08:04 AM
|
0
|
1
|
588
|
POST
|
I see what you mean. Thanks so much Dan. rasterlist5 = arcpy.ListRasters(StageAge + "_*")
for raster in rasterlist5:
print raster
output_mean = CellStatistics(rasterlist5, "MEAN", "DATA")
output_mean.save(env.workspace + "\\" + raster[:11] + "ann")
... View more
04-23-2018
06:11 AM
|
0
|
0
|
1351
|
POST
|
I know it works like as below. Just thought there would be a more elegant and economic way to put it using ListRasters rasterlist5 = [StageAge + "_t_srf_apr", StageAge + "_t_srf_aug", StageAge + "_t_srf_dec", StageAge + "_t_srf_feb", StageAge + "_t_srf_jan", StageAge + "_t_srf_jul", StageAge + "_t_srf_jun", \
StageAge + "_t_srf_mar", StageAge + "_t_srf_may", StageAge + "_t_srf_nov", StageAge + "_t_srf_oct", StageAge + "_t_srf_sep"]
output_mean = CellStatistics(rasterlist5, "MEAN", "DATA")
output_mean.save(OUTWorkspace + "\\" + raster[:11] + "ann")
... View more
04-23-2018
05:45 AM
|
0
|
2
|
1351
|
POST
|
Thank you Dan. yes, the print statement gives me the list of rasters I want to calculate the mean from. I thought I was giving the script the list of rasters with the variable rasterlist. I don't quite understand why it only processes the last raster in the list.
... View more
04-23-2018
05:35 AM
|
0
|
4
|
1351
|
POST
|
just to add that I'm using 10.2.1 at the moment. many thanks
... View more
04-23-2018
05:02 AM
|
0
|
0
|
1351
|
POST
|
Hi, I'm trying to run Mean annual cell statistics for groups of monthly rasters. The output I'm getting is the same as the last raster in the list ("camp_t_srf_sep" in this example) so i assume the script is not actually iterating through all rasters. Any help will be greatly appreciate it. # Example of list of rasters:
# camp_t_srf_apr
# camp_t_srf_aug
# camp_t_srf_dec
# camp_t_srf_feb
# camp_t_srf_jan
# camp_t_srf_jul
# camp_t_srf_jun
# camp_t_srf_mar
# camp_t_srf_may
# camp_t_srf_nov
# camp_t_srf_oct
# camp_t_srf_sep
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
env.overwriteOutput = True
env.extent = arcpy.Extent(-180.0, -90.0, 180.0, 90.0)
env.workspace = arcpy.GetParameterAsText(0)
StageAge = arcpy.GetParameterAsText(1)
rasterlist = arcpy.ListRasters(StageAge + "_*")
for raster in rasterlist:
output_mean = CellStatistics(raster, "MEAN", "DATA")
output_mean.save(env.workspace + "\\" + raster[:11] + "ann")
... View more
04-23-2018
03:07 AM
|
0
|
7
|
1922
|
Title | Kudos | Posted |
---|---|---|
1 | 11-06-2015 05:13 AM | |
1 | 11-09-2015 01:25 AM | |
1 | 11-12-2014 05:27 AM |
Online Status |
Offline
|
Date Last Visited |
07-12-2022
09:52 AM
|