POST
|
I'm trying to convert some 16 bit raster images to 8 bit. What I have done is saved my image files as ESRI GRIDS. I'll then planing on cycling through each band and scaling them to fit between 0-255. To do this, I need to store the min and max values from each band as a variable to use in some mathmatical functions. The min value for this exzample is "0" and the max is "9269". I get an error on the "b1plus" calcualtion stating "ERROR 000732: Input Raster: Dataset 0 does not exist or is not supported". The correct values are getting stored in "b1min" and "b1max". the calculation for "b1Numerator" works fine. doesn't like any of the calculations that involve the variables "b1min" or b1max". Any ideas out there? Thanks, Wade
b1min = (arcpy.GetRasterProperties_management("tempc1", "MINIMUM"))
b1max = (arcpy.GetRasterProperties_management("tempc1", "MAXIMUM"))
b1plus = arcpy.sa.Plus("tempc1", b1min)
b1Numerator = arcpy.sa.Times(b1plus, 255)
b1Denominator = arcpy.sa.Plus(b1max, b1min)
b1Int = arcpy.sa.Int(arcpy.sa.Divide(b1Numerator, b1Denominator))
b1Int.save("band1.tif")
... View more
08-29-2011
10:22 AM
|
0
|
0
|
306
|
POST
|
Would asking how to receive the data in a popup window be pushing my luck for today? Thought I could just implement the code you provided and be good to go until I found out the FetchSharedData() is inherited from the BaseWidget. Is there something similar to use in popups? Thanks, Wade
... View more
08-16-2011
12:38 PM
|
0
|
0
|
266
|
POST
|
I saw that as well. Guess that defeats the purpose of using the python call for what I'm trying to accomplish. I'm surprised the the function doesn't work the same as the export method from the TOC. Wade
... View more
08-16-2011
11:33 AM
|
0
|
0
|
349
|
POST
|
Robert, you cease to amaze me with what you can do in Flex 😄 Thank you so much for what you contribute on a day to day basis on these forums! It makes us hobby programmers spend less and less time wanting to take baseball bats to our computers 🙂 Wade
... View more
08-16-2011
10:18 AM
|
0
|
0
|
266
|
POST
|
Okay, dummy me. I had a line of code missing from the widget I was wanting to share data from ( the line "addSharedData("LayoutTitle", layoutArr);" apparently is pretty important). Everything works fine if I have the print widget set to preload. Is it possible to make this work without requiring the print widget to be preloaded? Wade
... View more
08-16-2011
09:45 AM
|
0
|
0
|
266
|
POST
|
I just checked that and changed it to preload. Cleared my cache as well. No luck.
... View more
08-16-2011
09:02 AM
|
0
|
0
|
442
|
POST
|
Wade, I have no problem changing the title in my test environment I set up for this. Are you possibly sending the addSharedData before the print widget is initialized? Where would I check that? Wade
... View more
08-16-2011
08:44 AM
|
0
|
0
|
442
|
POST
|
Is there a way to duplicate the functionality found when you right-click on a rster layer and choose "Export"? I'm trying to convert 32 bit images to 8 bit similar to the way you can check the Use Renderer and Froce RGB option in the Export Raster Data window. I've tried using CopyRaster_management, but the results I get from that tool are incorrect (I get a raster image where all the pixels have the same value: arcpy.CopyRaster_management("test", "C:/Temp/grids/test_8bit.tif", "", "", "", "", "ColormapToRGB", "8_BIT_UNSIGNED") I've tried every possible combination of parameters to no avail... Wade
... View more
08-16-2011
08:12 AM
|
0
|
3
|
2635
|
POST
|
<?xml version="1.0" encoding="utf-8"?>
<viewer:BaseWidget xmlns:esri="http://www.esri.com/2008/ags"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:mxeffects="com.adobe.ac.mxeffects.*"
xmlns:flash="flash.text.*"
xmlns:viewer="com.esri.viewer.*"
xmlns:widgets="widgets.*"
x="600" y="300"
widgetConfigLoaded="init()">
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.Map;
import com.esri.ags.events.GeometryServiceEvent;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.layers.Layer;
import com.esri.ags.symbols.SimpleFillSymbol;
import com.esri.ags.symbols.SimpleLineSymbol;
import com.esri.viewer.ViewerContainer;
import com.esri.viewer.AppEvent;
import flash.display.Sprite;
import flash.net.SharedObject;
import flash.printing.PrintJob;
import flash.text.TextField;
import mx.collections.ArrayCollection;
import mx.containers.Canvas;
import mx.controls.Alert;
import mx.controls.Image;
import mx.core.UIComponent;
import mx.graphics.ImageSnapshot;
import mx.graphics.codec.JPEGEncoder;
import mx.graphics.codec.PNGEncoder;
import mx.managers.CursorManager;
import mx.managers.PopUpManager;
import widgets.myPrint.PrintPreview;
import widgets.myPrint.layouts.A5_Landscape;
import widgets.myPrint.utils.PrintMapUtil;
//labels
[Bindable]
private var image:Image;
[Bindable]
private var graphic:Graphic;
[Bindable]
private var title:String;
[Bindable]
private var titleLabel:String;
[Bindable]
private var mapproduct:String;
[Bindable]
private var maptrait:String;
private function init():void
{
trace("MyPrintWidget init()");
AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);
}
private function sharedDataUpdated(event:AppEvent):void
{
var data:Object = event.data;
if (data.key == "LayoutTitle")
{
var theObj:Object = data.collection[0];
mapproduct = theObj.mapproduct;
maptrait = theObj.maptrait;
title = mapproduct + maptrait;
}
}
private function landscapePrintPreview():void
{
graphicsLayer.clear();
// create instance of our map layout
var mapLayout:A5_Landscape = new A5_Landscape();
mapLayout.initialize();
mapLayout.map = map;
mapLayout.inputTxt.text = title;
// Create the popup and set its map layout
var popup:PrintPreview = PrintPreview(PopUpManager.createPopUp(map,PrintPreview,false));
popup.mapLayout = mapLayout;
}
private function imageHandler(image:Image):void
{
map.zoomSliderVisible = false;
map.scaleBarVisible = false;
var graphic:Graphic = PrintMapUtil.trimmedExtent(map,
image.width,
image.height);
graphicsLayer.clear();
graphicsLayer.add(graphic);
image.source = PrintMapUtil.trimmedMap(map,
image.width,
image.height);
map.zoomSliderVisible = false;
map.scaleBarVisible = false;
}
private function widgetClosedHandler(event:Event):void
{
graphicsLayer.visible = false;
setMapNavigation(null, null);
}
private function widgetMinimizedHandler(event:Event):void
{
this.widgetClosedHandler(event);
}
private function widgetOpenedHandler(event:Event):void
{
graphicsLayer.visible = true;
}
]]>
</fx:Script>
<fx:Declarations>
<esri:SimpleFillSymbol id="sfs" color="0xE95020" alpha="1" style="solid">
<esri:SimpleLineSymbol color="0xFF0000" width="4" alpha="1" style="solid" />
</esri:SimpleFillSymbol>
<esri:GraphicsLayer id="graphicsLayer" symbol="{sfs}"/>
</fx:Declarations>
<viewer:WidgetTemplate id="wTemplate"
closed="widgetClosedHandler(event)"
open="widgetOpenedHandler(event)"
minimized="widgetMinimizedHandler(event)"
skinClass="com.esri.viewer.skins.WidgetTemplateSkin"
width="260" height="134">
<s:VGroup width="100%" height="100%" verticalAlign="top" horizontalAlign="center">
<mx:Form id="frmPrint" verticalScrollPolicy="off" paddingBottom="0" width="100%" height="86">
<s:HGroup horizontalAlign="center" width="100%" verticalAlign="middle">
<mx:Text id="labelTxt" text="Map Title: " textAlign="right"/>
<s:TextInput id="input" text="{title}"/>
</s:HGroup>
<s:HGroup horizontalAlign="center" width="100%">
<s:Button label="Print Preview" click="landscapePrintPreview()"/>
</s:HGroup>
</mx:Form>
</s:VGroup>
</viewer:WidgetTemplate>
</viewer:BaseWidget>
... View more
08-16-2011
07:35 AM
|
0
|
0
|
442
|
POST
|
Thanks Robert. Sorry for posting in this forum. Can't ever keep it straight of which to post which questions in. I've got that code implemented and it runs with no errors, but it's not populating a text box with the values when I save them in my title:String variable (highlighted in dark red).
private function init():void
{
trace("MyPrintWidget init()");
AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);
}
private function sharedDataUpdated(event:AppEvent):void
{
var data:Object = event.data;
if (data.key == "LayoutTitle")
{
var theObj:Object = data.collection[0];
mapproduct = theObj.mapproduct;
maptrait = theObj.maptrait;
title = mapproduct + maptrait;
}
}
private function widgetClosedHandler(event:Event):void
{
graphicsLayer.visible = false;
setMapNavigation(null, null);
}
private function widgetMinimizedHandler(event:Event):void
{
this.widgetClosedHandler(event);
}
private function widgetOpenedHandler(event:Event):void
{
graphicsLayer.visible = true;
}
]]>
</fx:Script>
<fx:Declarations>
<esri:SimpleFillSymbol id="sfs" color="0xE95020" alpha="1" style="solid">
<esri:SimpleLineSymbol color="0xFF0000" width="4" alpha="1" style="solid" />
</esri:SimpleFillSymbol>
<esri:GraphicsLayer id="graphicsLayer" symbol="{sfs}"/>
</fx:Declarations>
<viewer:WidgetTemplate id="wTemplate"
closed="widgetClosedHandler(event)"
open="widgetOpenedHandler(event)"
minimized="widgetMinimizedHandler(event)"
skinClass="com.esri.viewer.skins.WidgetTemplateSkin"
width="260" height="134">
s:VGroup width="100%" height="100%" verticalAlign="top" horizontalAlign="center">
<mx:Form id="frmPrint" verticalScrollPolicy="off" paddingBottom="0" width="100%" height="86">
<<s:HGroup horizontalAlign="center" width="100%" verticalAlign="middle">
<mx:Text id="labelTxt" text="Map Title: " textAlign="right"/>
<s:TextInput id="input" text="{title}"/>
</s:HGroup>
<s:HGroup horizontalAlign="center" width="100%">
<s:Button label="Print Preview" click="landscapePrintPreview()"/>
</s:HGroup>
</mx:Form>
</s:VGroup>
</viewer:WidgetTemplate>
</viewer:BaseWidget>
Thanks, Wade
... View more
08-16-2011
07:25 AM
|
0
|
0
|
442
|
POST
|
I have a custom query tool that was developed for me, and I would like to pass 2 combobox selections to a print widget to use as the title of a print template in a print widget. I have taken a look at the post where Robert explained how to do this (http://forums.arcgis.com/threads/13863-Communication-between-widgets?highlight=widget+communication), but I still seem to be having a bit trouble. the code I have put together is below. I think the problem may be in how I'm building my array in the custom query widget and/or how I'm trying to recall the items in the array in my print widget. Any suggestions out there?
// CUSTOM QUERY WIDGET
// share data
var layoutArr:ArrayCollection = new ArrayCollection();
layoutArr.addItemAt(String(cboLayerHybrid.selectedLabel), 0);
layoutArr.addItemAt(String(cboLayerTrait.selectedLabel), 1);
addSharedData("LayoutTitle", layoutArr);
// CUSTOM PRINT WIDGET
private function init():void
{
trace("MyPrintWidget init()");
AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);
}
private function sharedDataUpdated(event:AppEvent):void
{
var data:Object = event.data;
if (data.key == "LayoutTitle")
{
var theObj:Object = data.collection[0];
layoutArr.addItem(theObj);
mapproduct = layoutArr.getItemAt(0);
maptrait = layoutArr.getItemAt(1);
title = mapproduct + maptrait;
}
}
Thanks, Wade
... View more
08-16-2011
06:19 AM
|
0
|
16
|
3955
|
POST
|
Trying to put together a python script for converting my 5-band, 32 bit unsigned to image to a 3-band, 8 bit unsigned image. I'm doing this in conjunction with calculating an NDVI for each image as well. I start by converting the geo-tif to a ESRI GRID. The next part is what is breaking down for me (highlighted in dark red). I take the 3 raster bands (ESRI GRIDS) that I want to composite and convert them to 8 bit tif files. I then composite them in the order I want into a single. The problem that I am having is that each CopyRaster_management routine I run to convert the bands to 8 bit tif's produces a 8 bit file with all the pixels having the same value. I checked the GRID files and they are correct. Problem is happening in the coversion to 8 bit. NDVI routine runs fine as it continues to work fro the GRID files. Anybody see something that I'm missing?
import arcpy
import os
from arcpy import sa
from arcpy.sa import *
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("spatial")
inDIR = "C:/GIS_Projects/5_band/clipped"
bitDIR = "C:/GIS_Projects//images/bit_8"
ndviDIR = "C:/GIS_Projects/images/ndvi"
tmpDIR = "C:/Temp/grids"
arcpy.env.workspace = inDIR
rasters = arcpy.ListRasters("*", "TIF")
for raster in rasters:
arcpy.env.workspace = inDIR
print raster
fltname = raster[:-9]
rname = raster[:-9] + ".tif"
ndviname = raster[:-9] + "_ndvi.tif"
temp = "temp"
arcpy.CopyRaster_management(raster, os.path.join(tmpDIR,temp), "", "", "", "NONE", "NONE", "32_BIT_UNSIGNED")
print "Converting " + rname + " to 8 Bit Image"
arcpy.env.workspace = tmpDIR
arcpy.CopyRaster_management("tempc5", "band5.tif", "", "", "", "NONE", "ColormapToRGB", "8_BIT_UNSIGNED")
arcpy.CopyRaster_management("tempc3", "band3.tif", "", "", "", "NONE", "ColormapToRGB", "8_BIT_UNSIGNED")
arcpy.CopyRaster_management("tempc2", "band2.tif", "", "", "", "NONE", "ColormapToRGB", "8_BIT_UNSIGNED")
arcpy.CompositeBands_management("band5.tif;band3.tif;band2.tif", os.path.join(bitDIR,rname))
print "Converting " + rname + " to float"
arcpy.env.workspace = inDIR
arcpy.RasterToFloat_conversion(os.path.join(tmpDIR,temp + "c3"), os.path.join(tmpDIR, fltname + "_c3.flt"))
arcpy.RasterToFloat_conversion(os.path.join(tmpDIR,temp + "c5"), os.path.join(tmpDIR, fltname + "_c5.flt"))
arcpy.CopyRaster_management(os.path.join(tmpDIR, fltname + "_c5.flt"), os.path.join(tmpDIR, \
"nir.tif"), "", "", "", "NONE", "NONE", "32_BIT_FLOAT")
arcpy.CopyRaster_management(os.path.join(tmpDIR, fltname + "_c3.flt"), os.path.join(tmpDIR, \
"red.tif"), "", "", "", "NONE", "NONE", "32_BIT_FLOAT")
print "Calculating NDVI for " + rname
divide = arcpy.sa.Divide(arcpy.sa.Minus(tmpDIR + "/" + "nir.tif", \
tmpDIR + "/" + "red.tif"), arcpy.sa.Plus(tmpDIR + "/" + "nir.tif", tmpDIR + "/" + "red.tif"))
divide.save(os.path.join(ndviDIR, ndviname))
... View more
08-15-2011
12:27 PM
|
0
|
0
|
3260
|
POST
|
All: Was wondering the best way to go about calculating the average value for a column of data in a graphics layer. Would also like to return a count of the number of features in the graphics layer as well. Thanks, Wade
... View more
08-15-2011
06:10 AM
|
0
|
0
|
406
|
POST
|
How would this work if you had a multi-band tiff? Thanks, Wade
... View more
08-12-2011
07:15 AM
|
0
|
0
|
301
|
Title | Kudos | Posted |
---|---|---|
1 | 07-26-2011 07:57 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|