ThinkGeo.com    |     Documentation    |     Premium Support

The record is invalid, please call Validate method to check the failed reason.Record index: 1

Hi,


please help.


I am getting the following trying to load shape "The record is invalid, please call Validate method to check the failed reason.Record index: 1".


Some background - there are shapefiles containing information for projects. I need to create new shapefiles for each project. The shape files are created and there are no error or exceptions, but as soon as I try to load the shapefile I get the above error. Any information will be greatly appreciated. Below is the Code used to create and load the shape file.


Create



var



 sortedDic = (from entry in dicVals orderby entry.Key ascending select entry);foreach (KeyValuePair<string, string> kvp in sortedDic)string sProjectID = kvp.Key;string sProjextIDFld = kvp.Value;if (!sPath.EndsWith("\\"))"\\";".shp";switch (sType)case "Point":case "Multipoint":ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Multipoint, sPath, nulldbf); break;case "Line":case "Multiline":ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polyline, sPath, nulldbf);break;case "Polygon":case "Multipolygon":ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polygon, sPath, nulldbf);break;ShapeFileFeatureLayer.BuildIndexFile(sPath);ShapeFileFeatureLayer sl = new ShapeFileFeatureLayer(sPath, ShapeFileReadWriteMode.ReadWrite);foreach (Feature feature in shapeLayer.QueryTools.GetFeaturesByColumnValue(sProjextIDFld, sProjectID, ReturningColumnsType.NoColumns))TransactionResult result = sl.EditTools.CommitTransaction();"Features added to " + sPath + " = " + result.TransactionResultStatus.ToString());

 


Load



string


 


 


sPath +=


sPath += id +


 


 sPath = MapPath("~/futureprojects");string id = "3";if (!sPath.EndsWith("\\"))"\\";".shp";try

{


 


Map1.EditOverlay.FeatureSource.Open();


 


sl.Open();


sl.Validate();


Map1.EditOverlay.EditTools.BeginTransaction();


 


{


Map1.EditOverlay.EditTools.Add(f);


}


 


sl.Close();


}


 


{


 


}


ShapeFileFeatureLayer.BuildIndexFile(sPath);ShapeFileFeatureLayer sl = new ShapeFileFeatureLayer(sPath, ShapeFileReadWriteMode.ReadOnly);foreach (Feature f in sl.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns))TransactionResult result = Map1.EditOverlay.EditTools.CommitTransaction();catch (Exception ex)throw new Exception(ex.Message);

Thanks


Govin



 


 


{


 


 


 


 


sPath +=


sPath += id.ToString() +


 


{


 


 


 


;


 


 


 


 


 


 


 


 


 


}


 


 


sl.Open();


sl.EditTools.BeginTransaction();


 


{


sl.EditTools.Add(feature);


}


 


Response.Write(


sl.Validate();


 


sl.Close();


id++;


}


shapeLayer.Close();



 


Hi, Govin
 
I can’t see your codes clearly, please package it into one flat file or send us one solution that could re-create your problem, so that we can figure it out quickly.
 
Also please try to drag your shape files into Map Suite Explorer and to see whether it can be loaded, if not so I guess that there exists some problem for your shape files.
 
Thanks,
 
Khalil

Govin, 
  
 Here is a link outlining how to post source code and make it look nice and formatted. 
  
 gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/39/aft/7657/afv/topic/Default.aspx 
  
 David

Hi thanks for the reply, code below. 
 Create Shapefile 
  
var sortedDic = (from entry in dicVals orderby entry.Key ascending select entry);
            
            foreach (KeyValuePair<string, string> kvp in sortedDic)
            {
                string sProjectID = kvp.Key;
                string sProjextIDFld = kvp.Value;
                
                if (!sPath.EndsWith("\"))
                    sPath += "\";
                sPath += id.ToString() + ".shp";

                switch (sType)
                {
                    case "Point":
                    case "Multipoint":
                        ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Multipoint, sPath, nulldbf); 
;
                        break;
                    case "Line":
                    case "Multiline":
                        ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polyline, sPath, nulldbf);
                        break;
                    case "Polygon":
                    case "Multipolygon":
                        ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polygon, sPath, nulldbf);
                        break;
                }
                ShapeFileFeatureLayer.BuildIndexFile(sPath);
                ShapeFileFeatureLayer sl = new ShapeFileFeatureLayer(sPath, ShapeFileReadWriteMode.ReadWrite);
                sl.Open();
                sl.EditTools.BeginTransaction();

                foreach (Feature feature in shapeLayer.QueryTools.GetFeaturesByColumnValue(sProjextIDFld, sProjectID, ReturningColumnsType.NoColumns))
                {
                    sl.EditTools.Add(feature);
                }
                TransactionResult result = sl.EditTools.CommitTransaction();
                Response.Write("Features added to " + sPath + " = " + result.TransactionResultStatus.ToString());
                sl.Validate();
               
                sl.Close();
                id++;
            }
            shapeLayer.Close();
 
  
 Load Shape file 
  
        string sPath = MapPath("~/futureprojects");
        string id = "3";
        if (!sPath.EndsWith("\"))
            sPath += "\";
        sPath += id + ".shp";

        try
        {
            ShapeFileFeatureLayer.BuildIndexFile(sPath);
            Map1.EditOverlay.FeatureSource.Open();
            ShapeFileFeatureLayer sl = new ShapeFileFeatureLayer(sPath, ShapeFileReadWriteMode.ReadOnly);
            sl.Open();
            sl.Validate();
            Map1.EditOverlay.EditTools.BeginTransaction();
            foreach (Feature f in sl.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns))
            {
                Map1.EditOverlay.EditTools.Add(f);
            }
            TransactionResult result = Map1.EditOverlay.EditTools.CommitTransaction();
            sl.Close();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
 
  
  
 When I try and load the shapefile in map suite explorer, I get "Read and write not equal" error. 
  
 Thanks 
 Govin

sorted it out. 
  
 tx.

 


Hi Govin,
As far as I know from the codes, the error is caused by the code that creating the shapefile. For instance, creating Multiline shapefile looks like the below:
ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polyline, sPath, nulldbf);
 
The last parameter is “nulldbf”, which means that the shapefile doesn’t contains the dbf information. In other words, it’s unable to be used for spatial query, such as your code below, because there isn’t any other information except geometry data.


shapeLayer.QueryTools.GetFeaturesByColumnValue(sProjextIDFld, sProjectID, ReturningColumnsType.NoColumns)
 
Please add the “sProjextIDFld” column to dbf file if we want using it for spatial query.
 
Thanks,
 
Johnny
 

Hi Johnny, 
  
 thanks but I got it working already. 
  
 Thanks again for all the quick replies. 
  
 Regards 
 Govin

Great, any questions please feel free to post here. 
  
 Thanks, 
  
 Johnny