ThinkGeo.com    |     Documentation    |     Premium Support

Create ShapeFiles exception

Hi,


I tried to create a shape file, but following line of code always throws IOException:


ShapeFileFeatureSource.CreateShapeFile(ShapeFieType.Polyline,sShapeFilePath,New DbfColumn(){ column1,column2})


Following is the detailed message of the exception:


System.IO.IOException was unhandled

  Message="The process cannot access the file 'E:\TMPTest.dbf' because it is being used by another process."

 


The funny thing is sShapeFilePath="E:\Test.shp",  not "E:\TMPTest.shp",  why the error message says "E:\TMPTest.dbf" is being used by another process?

 


Thanks


Rose



Rose,  
  
 I couldn’t recreate your issue but after checking the source code, I think it might have a problem in certain cases. I changed the  code and in the upcoming version, it should be fine. Can you let me know more how to recreate your issue as maybe I can provide some workaround for now. 
  
 The reason it has the prefix “Tmp” is because when we create new shape files, we create a tmp file first (TMPTest.shp in this case)  and rename it to Test.shp later. In this way, if there are some accidents happened during this process (power is off for example), you will not have the corrupted Test.shp file. 
    
 Thanks, 
  
 Ben

Ben:


Is there a limitation on the no. of DbfColumns passed in to the ShapeFileFeatureSource.CreateShapeFile method? Or is there a limitation on the name of the Dbf column?


You can recreate the issue by passing in a column defined like this:


Dim IDColumn as New DfbColumn("aispolylines_id",DbfColumnType.Integer,10,0)


When change to the column name to "ID" instead of "aispolylines_id", it works.


Hope this helps you narrow down the problem!


Rose



Shapefile column names can only be 10 or 11 characters (I’ve seen all applications work with 10, but some fail with 11).   This is a limit of the DBase II .dbf file.

there is a 10 char limit per column name due to .dbf format … and it’s a pitty.

I have changed all the column names to make sure they have <=10 chars, but still throws the same exception. After looked into it, I found following column caused the trouble:



 



Dim startDateColumn As New DbfColumn("Date1", DbfColumnType.Date, 20, 0)

Is "Date" type column not supported?


Thanks


Rose




Rose,



I see your problem. The length of a Date type should be 8, so just change your length from 20 to 8 will be fine. Here is a DBF specification where you can find the description of a Date Type.



Date      8 bytes - date stored as a string in the format YYYYMMDD. 

dbase.com/KnowledgeBase/int/db7_file_fmt.htm


Very sorry we didn't throw a proper exception, that's defenitely a problem and we will add it in the coming version.



Thanks,



Ben