automation error - creating many polygon labels

634
0
07-03-2012 11:02 AM
DorisRiedl
New Contributor
I want to create polygon labels for about 40.000 polygons with all the polygon data copied to the point in ArcMap 10 SP4.
I use the  CalculatePolygonCentroid.getCentroids method below to calculate the labels. But I only succeed to calculate about 13500 and then I get  "Automation Exception: One or more arguments are invalid".
I used the Windows Resource Monitor to observe the CPU and Memory, but nothing seemed conspicuous (no value came near 100).

I also tried several other versions of the code below, e.g. with an Insert Cursor, but this only changed the amount of calculated labels minimally (I always stayed between 12735 and 13700).
I tried to work with a QueryFilter to only execute a subset of (5000 or 1000) and release the Cursor every time, before starting on the new set -> no substantial change.
I tried within an Edit Session - even stopping and starting editing after every subset and outside an Edit Session.

The polygon dataset has no topology errors, I checked this thoroughly.


import javax.swing.JOptionPane;

import com.esri.arcgis.geodatabase.IFeatureClass;
import com.esri.arcgis.geodatabase.IFeature;
import com.esri.arcgis.geodatabase.Feature;
import com.esri.arcgis.geodatabase.IFields;
import com.esri.arcgis.geodatabase.esriFieldType;
import com.esri.arcgis.geometry.Polygon;
import com.esri.arcgis.geodatabase.IFeatureCursor;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.geometry.IPoint;
import com.esri.arcgis.geodatabase.IQueryFilter;

import com.esri.arcgis.system.Cleaner;


public class CalculatePolygonCentroid {
    IFeatureClass polygons;
    IFeatureClass centroids;
    IFields centroidFields;
    
    
    public CalculatePolygonCentroid(IFeatureClass polygons, IFeatureClass centroids, IFields centroidFields){
        this.polygons = polygons;
        this.centroids = centroids;
        this.centroidFields = centroidFields;
    }
    
    public void getCentroids(){
        try{
            
            IFeature feature;
            Polygon polygon;
            Point centroid;
            Feature pointFeature;

            int j;
            int[][]compare = mapFields();
         
            IFeatureCursor polygonsCursor = polygons.search(null, false);
            
            while ((feature = polygonsCursor.nextFeature()) != null){
                
                polygon = (Polygon) feature.getShapeCopy();
                centroid = (Point) polygon.getLabelPoint();
                pointFeature = (Feature)centroids.createFeature();
                pointFeature.setShapeByRef((IPoint)centroid);
                              
                for(j = 0; j < compare.length; j++){
                    if (pointFeature.getFields().getField(compare[0]).isEditable() 
                            && pointFeature.getFields().getField(compare[0]).getType() != esriFieldType.esriFieldTypeGeometry){
                        pointFeature.setValue(compare[0], feature.getValue(compare[1]));
                        
                    }
                    
                }
                pointFeature.store();
            }
            Cleaner.release(polygonsCursor);
            
        }catch (Exception e){
            e.getStackTrace();
            JOptionPane.showMessageDialog(null, "Can't get Centroids! "+  e.getMessage());
            
        }
    }
    
    private int[][] mapFields(){
        try {
            IFields polyFields = polygons.getFields();
            IFields centroidFields = centroids.getFields();
            int [][] fieldsMap = new int [centroidFields.getFieldCount()][2];
               String polyfname;
               String centroidfname;
                for (int i = 0; i < fieldsMap.length; i++){
                    for (int j = 0; j < polyFields.getFieldCount(); j++){
                        centroidfname = centroidFields.getField(i).getName();
                        polyfname = polyFields.getField(j).getName();
                        if (centroidfname.equals(polyfname)){
                            {
                                fieldsMap[0] = i;
                                fieldsMap[1] = j;
                            }
                        }
                    }
                }
            
            return fieldsMap;
            
        }catch (Exception e){
            e.getStackTrace();
            JOptionPane.showMessageDialog(null, "Can't get Fieldmap!");
            int [][] fieldsMap = new int [1][2];
            fieldsMap [0][0]= 0;
            fieldsMap [0][1]= 0;
            return fieldsMap;
        }
    }
    

}



Do you have any ideas what I do wrong?


I am already a bit desperate by now, because it seems a straightforward enough task to do.
Doris
0 Kudos
0 Replies