0

I found createfishnet method in arcobject, but it doesn't work.Where is my mistake?

Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            ESRI.ArcGIS.DataManagementTools.CreateFishnet fishnet = new ESRI.ArcGIS.DataManagementTools.CreateFishnet();
            fishnet.template = buffer_out;
            //txtOutputPath2.Text="E:\\program\\shenzhen_science_committee\\sc\\landuse_subway\\shenzhen_subway\\23_net.shp"

            fishnet.out_feature_class = txtOutputPath2.Text;
            IFeatureCursor cursor1=buffer_out.Search(null,true);
            IFeature buffer=cursor1.NextFeature();
            IPoint centerPoint =new ESRI.ArcGIS.Geometry.Point();
            IArea pArea = buffer.Shape as IArea;  
            pArea.QueryCentroid(centerPoint);
            fishnet.origin_coord = centerPoint;
            double height=0;
            double width=0;
            fishnet.cell_height = 0.1;
            fishnet.cell_width = 0.1;
            fishnet.number_columns = 50;
            fishnet.number_rows = 50;

            IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(fishnet, null);

The result shows wrong HRESULT E_FAIL.

k.xf
  • 359
  • 1
  • 3
  • 10

1 Answers1

0

I have tried this in ArcObjects with Java. What I found was that the fishnet could not be generated for area within a particular polygon, as in the ArcMap application. You would have to intersect or use spatial filter on the fishnet output. Also, try giving all the parameters, even the optional ones like set corner coordinate. If you are using data in a particular projection system, that can be set to the output by setting the template (and this takes only Envelope).

Below is the code that I have used. I wanted the fishnet label as well, so I have enabled it. Make sure you use a space between the x and y coordinate of a point, entered as a String, which is probably the issue here.

GeoProcessor gp = new GeoProcessor();
gp.setOverwriteOutput(true);

IEnvelope aoi = buffer_out.getEnvelope();
CreateFishnet createFishnet = new CreateFishnet(); 
createFishnet.setOutFeatureClass(tempDir+"/"+fishnetOutput+".shp");
createFishnet.setTemplate(aoi);
createFishnet.setOriginCoord(aoi.getXMin()+" "+aoi.getYMin());
createFishnet.setYAxisCoord(aoi.getXMin()+" "+aoi.getYMax());
createFishnet.setCornerCoord(aoi.getXMax()+" "+aoi.getYMax());
createFishnet.setCellHeight(30.0);                  
createFishnet.setCellWidth(30.0);
createFishnet.setNumberRows(0);
createFishnet.setNumberColumns(0);
createFishnet.setLabels("LABELS");
createFishnet.setGeometryType("POLYLINE");

gp.execute(createFishnet, null);

I hope you can use this example and apply it to your code.