def testGetDBFInfo(self): """Fetch dbf information from shapefile""" sf = mapscript.shapefileObj('../../../../tests/polygon.shp') assert sf.getDBF() != None, sf.getDBF() assert sf.getDBF().nFields == 2, sf.getDBF().nFields assert sf.getDBF().getFieldName(0) == 'FID', sf.getDBF().getFieldName(0) assert sf.getDBF().getFieldName(1) == 'FNAME', sf.getDBF().getFieldName(1)
def testGetDBFInfo(self): """Fetch dbf information from shapefile""" pth = os.path.join(TESTS_PATH, "polygon.shp") sf = mapscript.shapefileObj(pth) assert sf.getDBF() != None, sf.getDBF() assert sf.getDBF().nFields == 2, sf.getDBF().nFields assert sf.getDBF().getFieldName(0) == 'FID', sf.getDBF().getFieldName(0) assert sf.getDBF().getFieldName(1) == 'FNAME', sf.getDBF().getFieldName(1)
def testGetDBFInfo(self): """Fetch dbf information from shapefile""" sf = mapscript.shapefileObj('../../../../tests/polygon.shp') assert sf.getDBF() != None, sf.getDBF() assert sf.getDBF().nFields == 2, sf.getDBF().nFields assert sf.getDBF().getFieldName(0) == 'FID', sf.getDBF().getFieldName( 0) assert sf.getDBF().getFieldName( 1) == 'FNAME', sf.getDBF().getFieldName(1)
def testAddEmpty(self): """expect an error rather than segfault when adding an empty shape""" # See bug 1201 sf = mapscript.shapefileObj('testAddDud.shp', 1) so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT) self.assertRaises(mapscript.MapServerError, sf.add, so)
from random import random from testing import mapscript # Get Number of shapes from the command line try: opts, args = getopt.getopt(sys.argv[1:], 'n:') except getopt.GetoptError: sys.exit(2) numshapes = 100 # default to 100 for o, a in opts: if o == '-n': numshapes = int(a) # The shapefileObj shpfile = mapscript.shapefileObj('timing.shp', mapscript.MS_SHAPEFILE_POLYGON) # Inline feature layer ilayer = mapscript.layerObj() ilayer.type = mapscript.MS_LAYER_POLYGON ilayer.setProjection('init=epsg:4326') ilayer.status = mapscript.MS_DEFAULT ilayer.connectiontype = mapscript.MS_INLINE print numshapes, "shapes" i = 0 while i < numshapes: # The shape to add is randomly generated xc = 4.0*(random() - 0.5) yc = 4.0*(random() - 0.5)