Really I don't understand loops in Java
;-)

2013/6/26 Giuseppe Aruta <giuseppe_ar...@yahoo.it>

> Hi Stefan,
> I made some progress, now I am able to save to asc, unfortunately each
> value of the pixel of the ascii is saved an incredible number equal to
> rowXcolumn of the original. So my test file of 101 byte becomes a huge file
> of 2 Gb :-( Surelly I made a misake.
> Then I moved to Switzerland for job, where actully I am. And didn't carry
> with me Eclipse, codes, OpenJMP, etc. I will be back home after 5th of July
> and give a better look (and send the code)
> regards
>
> Peppe
>
>
> 2013/6/26 Stefan Steiniger <sst...@geo.uzh.ch>
>
>> Hi Peppe,
>>
>> did you made any progress on that?
>> Or is the code the last version you have?
>>
>> slds,
>> stefan
>>
>> Am 21.06.13 06:05, schrieb Giuseppe Aruta:
>> >
>> > Hi all,
>> > Recently I worked a bit with Sextante/grids and did some specialized
>> > short courses. A student of mine used OpenJUMP/Sextante to do some
>> > analysis. Than he had to convert all the rasters (TIFF format) into ESRI
>> > Ascii grid files (.asc) as he had to use a more specialized software
>> > that was accepting only asc. and surfer raster format.
>> > Of coarse we used gdal for raster transformation.
>> > Well, since  Esri ascii file is a very simple text file
>> > (http://en.wikipedia.org/wiki/Esri_grid), in these days ( that I have
>> > spare time)  I tried to make a plugin "Export raster to Esri Ascii grid
>> > file" for OpenJUMP (that in turn I would like to add to OJ NB). All
>> > raster parameters are easy implemented by RasterImageLayer and
>> > OpenJUMPSextanteRasterLayer.
>> > I had some success and some failures.
>> > I ask your help, as developers.
>> > I added to this mail the code I wrote (coping partially OJ raster
>> > classes and from other software like ImageJ) - The foillowing code just
>> > shows the transformation, excluding initialize(), icon(), name(), etc.
>> > This code partially works: the file is saved together with the header of
>> > the raster (see the *black* part of the code, number of colums, rows,
>> > x-ycoordinates of upper left corner, cell size and NODATA),
>> > The red part of code is not working. This part should  lists the raster
>> > values for each cell, starting at the upper-left corner, possibly with
>> > decimal values, delimited by space character. I ask you if can give me a
>> > suggestion for this part.
>> > Another part that I would like to implement is the MultienableCheck
>> > (dark *violet *part of the code). This plugin should be activated only
>> > if the raster has only one band (I think this is numbered "0" by
>> > OpenJUMPSextanteRasterLayer class). Any suggestion is accepted: a way to
>> > distinguish (within Pirol raster plugin) between grid mono band file and
>> > others would be quite usefull for future plugins
>> > If this plugin is finished I think I will add to OJ NB under
>> > Raster>Tools menu.
>> > regards and thanks
>> >
>> > Peppe
>> >
>> > public class SaveToASCPlugIn extends AbstractPlugIn
>> > {
>> >
>> >    protected double[][] data;
>> >    private Properties properties = null;
>> >    private static String propertiesFile =
>> > LoadSextanteRasterImagePlugIn.getPropertiesFile();
>> >    private String lastPath;
>> >    NumberFormat cellFormat = null;
>> >    public static final String DEFAULT_NODATA = "-9999";
>> >
>> >    public boolean execute(PlugInContext context)
>> >      throws Exception
>> >    {
>> >      JFileChooser fc = new JFCWithEnterAction();
>> >
>> >      fc.setFileFilter(new FileFilter() {
>> >        public boolean accept(File f) {
>> >          return (f.isDirectory()) ||
>> >            (f.getName().toLowerCase().endsWith(".asc"));
>> >        }
>> >
>> >        public String getDescription() {
>> >          return "Arc/Info ASCII Grid (.asc)";
>> >        }
>> >      });
>> >      this.properties = new Properties();
>> >      try {
>> >        FileInputStream fis = new FileInputStream(propertiesFile);
>> >        this.properties.load(fis);
>> >        this.lastPath =
>> > this.properties.getProperty(LoadSextanteRasterImagePlugIn.KEY_PATH);
>> >        fis.close();
>> >      }
>> >      catch (FileNotFoundException e) {
>> >
>> >
>> context.getWorkbenchFrame().warnUser(I18N.get("org.openjump.core.ui.plugin.layer.pirolraster.SaveRasterImageAsImagePlugIn.File-not-found"));
>> >      }
>> >      catch (IOException e) {
>> >        context.getWorkbenchFrame().warnUser(GenericNames.ERROR);
>> >      }
>> >
>> >      if (this.lastPath != null) {
>> >        fc.setCurrentDirectory(new File(this.lastPath));
>> >      }
>> >      fc.setMultiSelectionEnabled(false);
>> >
>> >      fc.setDialogTitle(getName());
>> >      int returnVal = fc.showSaveDialog(fc);
>> >      if (returnVal == 0) {
>> >        String ascFileName = fc.getSelectedFile().getAbsolutePath();
>> >
>> >        if (!ascFileName.toLowerCase().endsWith(".asc".toLowerCase())) {
>> >            ascFileName = ascFileName + ".asc";
>> >        }
>> >
>> >        File ascFile = new File(ascFileName);
>> >
>> >        FileOutputStream ascOut = new FileOutputStream(ascFile);
>> >
>> >        RasterImageLayer rLayer =
>> > (RasterImageLayer)LayerTools.getSelectedLayerable(context,
>> > RasterImageLayer.class);
>> >        OpenJUMPSextanteRasterLayer rstLayer = new
>> > OpenJUMPSextanteRasterLayer();
>> >        rstLayer.create(rLayer);
>> >
>> > *PrintStream o = new PrintStream(ascOut);*
>> > *o.println( "ncols " + rLayer.getOrigImageWidth()  );
>> >                  //rstLayer.getNX()  );
>> >          o.println( "nrows " + rLayer.getOrigImageHeight()  );
>> >                  //rstLayer.getNY() );
>> >          o.println( "xllcorner " + rLayer.getEnvelope().getMinX() );
>> >          o.println( "yllcorner " + rLayer.getEnvelope().getMinY());
>> >          o.println( "cellsize " + rstLayer.getLayerCellSize() );
>> >          o.println( "NODATA_value " + DEFAULT_NODATA  );*
>> >
>> >
>> >      GridWrapperNotInterpolated gwrapper = new
>> > GridWrapperNotInterpolated(rstLayer, rstLayer.getLayerGridExtent());
>> >
>> >
>> >               int nx = rstLayer.getLayerGridExtent().getNX();
>> >              int ny = rstLayer.getLayerGridExtent().getNY();
>> >               for (int x = 0; x < nx; x++) {//cols
>> >                  for (int y = 0; y < ny; y++) {//rows
>> >                      double value = gwrapper.getCellValueAsFloat(x, y,
>> 0);
>> >                      StringBuffer b = new StringBuffer();
>> >                      for( int i = 0; i < rLayer.getOrigImageWidth();
>> i++ )
>> >                      {
>> >                          if( Double.isNaN(rstLayer.getNoDataValue()  )
>> > ) b.append( rstLayer.getNoDataValue() );
>> >                          else if( cellFormat != null ) b.append(
>> > cellFormat.format( value ));
>> >                          else b.append( cellFormat.format( value ) );
>> >                          if( i < rLayer.getOrigImageWidth() -1 )
>> > b.append(  " "  );
>> >                      }
>> >                      o.println( b );
>> >               }
>> >          }
>> >          o.close();
>> >
>> >        rLayer.setImageFileName(ascFileName);
>> >        rLayer.setNeedToKeepImage(false);
>> >      }
>> >
>> >      return true;
>> >    }
>> >
>> >
>> >    public void setCellFormat( NumberFormat format )
>> >      {
>> >          cellFormat = format;
>> >      }
>> >
>> >
>> > *public static MultiEnableCheck createEnableCheck(WorkbenchContext
>> > workbenchContext)
>> >    {
>> >      EnableCheckFactory checkFactory = new EnableCheckFactory(
>> >        workbenchContext);
>> >      MultiEnableCheck multiEnableCheck = new MultiEnableCheck();
>> >
>> >
>> >
>> multiEnableCheck.add(checkFactory.createExactlyNLayerablesMustBeSelectedCheck(1,
>> > RasterImageLayer.class));
>> >
>> >      return multiEnableCheck;*
>> >    }
>> >
>> > }
>> >
>> >
>> >
>> ------------------------------------------------------------------------------
>> > This SF.net email is sponsored by Windows:
>> >
>> > Build for Windows Store.
>> >
>> > http://p.sf.net/sfu/windows-dev2dev
>> >
>> >
>> >
>> > _______________________________________________
>> > Jump-pilot-devel mailing list
>> > Jump-pilot-devel@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>> >
>>
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by Windows:
>>
>> Build for Windows Store.
>>
>> http://p.sf.net/sfu/windows-dev2dev
>> _______________________________________________
>> Jump-pilot-devel mailing list
>> Jump-pilot-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>
>
>
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to