POST
|
Duncan - thanks for the suggestion. I tried to use SetNull, both in the map algebra expression, as well as in the geoprocessing method (after the Clip tool), and it does not change the result. As I understand SetNull, it doesn't change which value is treated as NoData, but rather changes individual cell values to the NoData value. Correct me if I'm wrong on that. Eric, Just a thought, if you have used the geoprocessing clip tool could you not then use the SetNull tool after the clip, if the ISaveAs is not working? Duncan I still think the IRasterProps/ISaveAs approach should work. It's prescribed by ESRI (http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000000w6000000). As far as I can tell, there must be a bug in the NoData property of IRasterProps or in the SaveAs method of ISaveAs. Can anyone tell me if I'm doing something wrong? Or does anyone know of a workaround?
... View more
08-21-2012
05:54 AM
|
0
|
0
|
445
|
POST
|
I want to clip a raster and retain the NoData value from the source raster in the clipped raster. In the method below, I follow these steps: (1) use map algebra to clip the source raster to the new extent (2) use IRasterProps to set the pixel type and NoData value to be the same as the source raster (3) use ISaveAs to save the new raster dataset The source raster I've been testing with is a 16-bit signed integer raster with a NoData value of -32768. Setting the pixel type works correctly, but the NoData value always ends up being 32767. I have also tried using the geoprocessing clip method (http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_clip_a_raster_dataset_with_an_envelope_or_a_dataset/0001000000n5000000/), but I still end up with 32767. (Other specifics in my testing that may or may not be relevant: input raster is GRID, output is file geodatabase) public static IRaster ClipRaster(IRaster2 sourceRaster, IEnvelope extent, IWorkspace workspace, string rasterName, string rasterFormat)
{
//map algebra method for clipping
//NoData value is not set properly (always ends up as largest positive integer supported by pixel type)
//clip
SetRasterAnalysisEnvCellSize(sourceRaster, true);
SetRasterAnalysisEnvExtent(extent, sourceRaster, true);
IMapAlgebraOp mapAlgebraOp = new RasterMapAlgebraOpClass();
string rasterSymbol = "source";
mapAlgebraOp.BindRaster((IGeoDataset)sourceRaster, rasterSymbol);
IGeoDataset tempClipRaster = mapAlgebraOp.Execute("[" + rasterSymbol + "]");
//set pixel type and nodata value to match input raster and save
IRasterProps propsClip = tempClipRaster as IRasterProps;
IRasterProps propsSource = sourceRaster as IRasterProps;
propsClip.PixelType = propsSource.PixelType;
propsClip.NoDataValue = propsSource.NoDataValue; // this doesn't stick
IRasterDataset3 clipOutput = ((ISaveAs2)tempClipRaster).SaveAs(rasterName, workspace, rasterFormat) as IRasterDataset3;
//delete the temporary dataset created by the map algebra op
if (((IDataset)((IRaster2)tempClipRaster).RasterDataset).CanDelete())
((IDataset)((IRaster2)tempClipRaster).RasterDataset).Delete();
IRaster outRaster = clipOutput.CreateDefaultRaster();
//IRaster outRaster = clipOutput.CreateFullRaster(); //this method has same result
return outRaster;
}
... View more
08-20-2012
12:37 PM
|
0
|
4
|
4055
|
POST
|
This was discussed last week in this thread: http://forums.arcgis.com/threads/63883-Can-AddIn-target-somehow-set-to-be-10.x Someone from ESRI suggested pointing the Config.esriaddinx to version 10.0 and recompiling, but that didn't work for a couple of us (caused ArcMap to crash on startup on the 10.0 computer). Does it work for you?
... View more
08-15-2012
07:23 AM
|
0
|
0
|
161
|
POST
|
Also, I dont' think that code will work if you have to change the projection of your data frame to WGS coordinates. +/- 5 in WGS will probably not give you what you expect. Does it? Since he's adding and subtracting from screen coordinates (before the toMapPoint transformation), the type of coordinate system shouldn't matter, right? I think that's the best way to do it; it should work as expected regardless of zoom level or of coordinate system.
... View more
08-14-2012
05:01 AM
|
0
|
0
|
248
|
POST
|
Rather than passing the point to the Identify method, you'll probably want to pass a small envelope or circle (centered on the click point) to tolerate the click being a slight distance from the feature. What type of features are you identifying? Polygons, lines, points? If points or lines, then passing a small envelope could be your solution. If you're working with polygons and a click right in the center is still resulting in a null array, there must be some other problem.
... View more
08-13-2012
12:02 PM
|
0
|
0
|
248
|
POST
|
In the Visual Studio Add-in 10.1 project, open the Config.esriaddinx file and change the version to 10.0. Then recompile the project, select 'No' to ignore the 'update'. The newly created add-in file ('esriAddIn') can be used to install on ArcGIS 10.0 system. But, again, if there's anything in the addin using new 10.1 functionality, it won't work on 10.0. I have recently upgraded to 10.1, and I tried these steps to build an add-in for users still on 10.0, and it doesn't seem to work. On the 10.0 computer we tested it on, the add-in installs successfully, but ArcMap crashes on startup. I have made minimal changes since upgrading; I'm just about certain there's no "new 10.1 functionality." I never should have moved to 10.1 in the first place, and I'll probably just revert back to 10.0 unless anyone can offer a solution.
... View more
08-10-2012
06:43 AM
|
0
|
0
|
909
|
POST
|
What line causes the exception? Is it when you create the new gxCatalogClass object, or does it occur at some point after those two lines of code? Are your references updated to the 10.1 SDK? For example, the ESRI.ArcGIS.Catalog namespace's path should be: C:\Program Files\ArcGIS\DeveloperKit10.1\DotNet\ESRI.ArcGIS.Catalog.dll I don't think this is your problem (since I guess you would have compile errors and wouldn't even be able to build the project), but you might want to verify anyway.
... View more
08-03-2012
09:52 AM
|
0
|
0
|
531
|
POST
|
Hi, I have code running in 10.0: Dim pGxObject As ESRI.ArcGIS.Catalog.IGxObject pGxCatalog = New ESRI.ArcGIS.Catalog.GxCatalogClass This gives me an error message upon upgrading to 10.1, it appears GxCatalogClass no longer exists. Anyway to make my code work in 10.1? I'm trying to gain access to the GetObjectFromFullName method. Thanks, Pete GxCatalogClass definitely still exists in the ESRI.ArcGIS.Catalog namespace: http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//00140000002p000000 I have upgraded to 10.1, and the catalog object in the add-in I'm currently working on is still working the same as it did before. I notice in your code that you're declaring a variable, pGxObject, and then initializing a variable, pGxCatalog. Shouldn't those be the same?
... View more
08-03-2012
06:59 AM
|
0
|
0
|
531
|
POST
|
Have you already gotten a reference to the feature layer from the table of contents? If so, cast the feature layer to the IFeatureSelection interface, and use that interface's SelectionSet property: ISelectionSet selectedFeatures = ((IFeatureSelection)featureLayer).SelectionSet You can then use a cursor over the selection set to access the individual features in the selection.
... View more
07-26-2012
10:07 AM
|
0
|
0
|
1539
|
POST
|
I have the following method for writing pixel edits to a raster:
private void RectangularRasterEdit(IRaster raster, IPnt topLeft, int widthInCells, int heightInCells, List<int> newPixelValues)
{
//rasterband
//IRasterBand rasterBand = ((IRasterBandCollection)raster).Item(0);
//pixel block size
IPnt blockSize = new PntClass();
blockSize.X = widthInCells;
blockSize.Y = heightInCells;
//create pixel block
//IPixelBlock pixelBlock = ((IRawPixels)rasterBand).CreatePixelBlock(blockSize);
IPixelBlock pixelBlock = raster.CreatePixelBlock(blockSize);
//build array of new values to be written to raster
short[,] pixels = new short[widthInCells, heightInCells];
int newValueIndex = 0;
for (int i = 0; i < widthInCells; i++)
{
for (int j = 0; j < heightInCells; j++)
{
pixels[i, j] = (short)newPixelValues[newValueIndex];
newValueIndex++;
}
}
//update pixel block with new pixel array
((IPixelBlock3)pixelBlock).set_PixelData(0, pixels);
//write changed pixelblock to raster
//((IRawPixels)rasterBand).Write(topLeft, pixelBlock);
((IRasterEdit)raster).Write(topLeft, pixelBlock);
((IRasterEdit)raster).Refresh();
}
This method can handle rectangles of any size, but I use it mostly for one-cell edits (pixelBlock is 1 X 1). The problem is that when I try to edit a cell in the rightmost column or in the bottom row of the raster, the IRasterEdit.Write method fails (with a generic HRESULT). I have tried the IRawPixels.Write method as well (the code for that is in comments above), but get the same error. For example, say I have a raster that is 6 pixels by 6 pixels. If I pass a 1X1 pixelBlock to the write method, and the top left corner contains a 5 for either the row or column, it fails. Also, after some testing, I verified that there is no problem reading a 1X1 pixel block using the same top left corner. The problem only occurs when trying to write. Any ideas what might be causing this issue?
... View more
07-23-2012
12:02 PM
|
0
|
0
|
233
|
POST
|
Eric, I don't see an option to "execute code from the clipboard" when I right click in the interactive window. See attached .jpg... What version of PythonWin are you using? I have v2.5 (build 210). P.S. Yes I realize this topic was hijacked... Sorry. Chris, I should have specified...I'm using build 212. It shows up right between "copy" and "paste."
... View more
12-21-2010
08:22 AM
|
0
|
0
|
351
|
POST
|
BTW: Does anyone know of a Python IDE (or a method in PythonWin) that lets you execute blocks of code all at once (copy and paste a bunch of code into an "Interactive Window" and then execute it)???? I found you can do this in the Python Window in ArcMap, but as of yet I can't find a way to do it in PythonWin. In pythonwin, you can copy a block of code from a script, then right click in the interactive window, and select "execute code from the clipboard." It doesn't paste the code; it just runs. So if the block of code doesn't have any output (print statements), it will run, but nothing will appear to happen in the interactive window. It won't allow any "unexpected indents" so you'll have to dedent the block of code before copying if it's inside a loop.
... View more
12-07-2010
09:58 AM
|
0
|
0
|
442
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|