10

Does anyone know where I can find a sample shapefile that has null entries in it (preferably a polygon shapefile)?

I'm not sure how to create one with null entries.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Jeff Storey
  • 1,067
  • 1
  • 11
  • 17

3 Answers3

10

I assume you mean null for the geometry/shape column, because shapefiles don't support null for any field type except the geometry and (i hear) for date fields.

The code below creates 1 shapefile with 1 record/feature that has a null poly geometry.


  import arcpy
  import os
  outfc = r'c:\temp\outfc.shp'
  arcpy.env.workspace = os.path.dirname(outfc)
  arcpy.CreateFeatureclass_management(arcpy.env.workspace,os.path.basename(outfc), 'polygon')
  cur = arcpy.InsertCursor(outfc)
  row = cur.newRow()
  cur.insertRow(row)
  del(row)
  del(cur)
  r = arcpy.CheckGeometry_management(outfc,'in_memory\\outtable')
  print r.getMessages()



I run it and get this which is what i'd expect

WARNING 000442: null geometry at 0 in c:\temp\outfc.shp

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
gotchula
  • 3,203
  • 1
  • 16
  • 18
10

Be warned that a lot of software reading SHP files do not support null-values for the geometry. Even older versions of ArcView had problems.

I have created a sample here: http://www.routeware.dk/temp/shp_null_sample.zip It has 3 records, the 2nd has no geometry.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Uffe Kousgaard
  • 2,543
  • 15
  • 24
  • Which versions of ArcView? I recall that AV 2.x and 3.x would create null geometries whenever they created a new shapefile ('FTab' object in Avenue), so null geometries were common and completely supported. – whuber Jan 18 '11 at 14:40
  • null geoms are supported, they're a valid value (unknown) for a geometry. Trouble is lots of software use the geometry without first checking if it's null, then bad things happen such as crashes . That's why there is a gp tool Data Management\CheckGeometry, if the software has trouble with a fc, this is typically the first thing to check. – gotchula Jan 18 '11 at 17:42
  • I don't quite remember. AV3 or AV8 perhaps? A new SHP file has no records at all, that isn't the same as a null geometry. – Uffe Kousgaard Jan 19 '11 at 08:54
  • 1
    It's a simple matter to add new records to a new shapefile (ctrl-A in the View GUI of AV 3.x will do it). They automatically have null shapes. Null shapes were also produced as the result of invalid operations, such as hard-projecting shapes that are outside the domain of a projection. AV 3.x generally had no problems with them. I think problems may have arisen in AV 8 and later: in effect, ESRI's newer software did not conform to their own specs. – whuber Jan 19 '11 at 18:20
  • I don't need it but the link in this answer is broken. – PolyGeo Jun 03 '16 at 03:49
  • 1
    @UffeKousgaard, I have applied a strikethrough to the portion of this post which pertained to a link which is now dead. Can you please elaborate on this answer to prevent removal of the post, which may result in lost reputation. – Fezter Mar 20 '17 at 22:29
  • 1
    The file is back. – Uffe Kousgaard Mar 21 '17 at 05:58
1

If you are working on ESRI software, at least I can speak for ArcGIS 9.3, then shapefiles do not support nulls. I ran into this problem a few weeks ago and spent a day investigating. I found this link particularly illuminating http://forums.esri.com/Thread.asp?c=93&f=993&t=125464. It seems the only way to support nulls within ESRI shapefiles is to use geodatabases (then the shapefiles become featureclasses. I used file a geodatabase). To support nulls, I ended up making a geodatabase and creating the featureclasses (otherwise known as shapefiles) inside the file geodatabase (this will support nulls) as opposed to creating a shapefile and then importing it into the geodatabase (this will not support nulls). If I remember correctly, you also have to explicitly state in the field properties that you want nulls to be supported. Here is the link that might help How to create a feature class in a file geodatabase in ArcGIS 9.3 with Python?

9monkeys
  • 183
  • 1
  • 6