Skip to content
Permalink
Browse files

Add new getItemDefinition to layerObj SWIG bindings and include tests

  • Loading branch information...
geographika committed Mar 16, 2019
1 parent 0260296 commit 2ac55eabdacef7df09ff9573aa5faef074e143bf
Showing with 101 additions and 2 deletions.
  1. +70 −0 mapscript/python/tests/cases/layer_test.py
  2. +27 −1 mapscript/swiginc/layer.i
  3. +4 −1 tests/test.map
@@ -58,6 +58,76 @@ def testLayerConstructorMapArg(self):
assert layer.map is not None, layer.map


class LayerItemDefinitionTestCase(MapLayerTestCase):

def setUp(self):
MapTestCase.setUp(self)
self.layer = self.map.getLayerByName('POINT')
self.layer.open()

def tearDown(self):
self.layer.close()

def testLayerGetItemDefinition(self):
"""test getting layer item information for the first item"""

gml_item = self.layer.getItemDefinition(0)
assert gml_item.name == "FID"
assert gml_item.type == "Integer"
assert gml_item.alias is None
assert gml_item.encode == 1
assert gml_item.minOccurs == 0
assert gml_item.outputByDefault == 1
assert gml_item.precision == 0
assert gml_item.template is None
assert gml_item.visible == 0
assert gml_item.width == 10

def testLayerGetItemDefinition2(self):
"""test getting layer item information for the second item"""

gml_item = self.layer.getItemDefinition(1)
assert gml_item.name == "FNAME"
assert gml_item.type == "Character"
assert gml_item.alias is None
assert gml_item.encode == 1
assert gml_item.minOccurs == 0
assert gml_item.outputByDefault == 1
assert gml_item.precision == 0
assert gml_item.template is None
assert gml_item.visible == 0
assert gml_item.width == 10

def testLayerGetMissingItemDefinition(self):
"""test getting item information for a non-existent index"""
gml_item = self.layer.getItemDefinition(100)
assert gml_item is None

def testLayerGetItemDefinitionClosedLayer(self):
"""item definition will be None for a closed layer"""
self.layer.close()
gml_item = self.layer.getItemDefinition(0)
assert gml_item is None

def testLayerGetNonDefinedItemDefinition(self):
"""test getting layer item information for a layer with gml_types auto"""

layer = self.map.getLayerByName('POLYGON')
layer.open()
gml_item = layer.getItemDefinition(0)
assert gml_item.name == "FID"
assert gml_item.type is None
assert gml_item.alias is None
assert gml_item.encode == 1
assert gml_item.minOccurs == 0
assert gml_item.outputByDefault == 1
assert gml_item.precision == 0
assert gml_item.template is None
assert gml_item.visible == 0
assert gml_item.width == 0
layer.close()


class LayerCloningTestCase(MapLayerTestCase):

def testLayerCloning(self):
@@ -685,5 +685,31 @@
self->_geomtransform.type = MS_GEOMTRANSFORM_NONE;
self->_geomtransform.string = NULL;
}
}
}

%feature("autodoc", "3");
%feature("docstring") "Returns the requested item's field definition.
A layer must be open to retrieve an item definition.
A field definition object includes the following properties:
name, type, alias, encode, minOccurs, outputByDefault, precision
template, visible, and width.
The numitems property contains the number of items
available, and the first item is index zero."

gmlItemObj *getItemDefinition(int i)
{

if (i >= 0 && i < self->numitems) {
gmlItemListObj *item_list;
item_list = msGMLGetItems(self, "G");
gmlItemObj *item = item_list->items + i;
return item;
}
else {
return NULL;
}

}


}
@@ -140,6 +140,9 @@ MAP
END
STATUS OFF # DEFAULT
DATA "point"
METADATA
"gml_types" "auto"
END
CLASSITEM "FNAME"
LABELITEM "FNAME"
CLASS
@@ -173,7 +176,7 @@ MAP
END
END
END

LAYER
NAME "INLINE"
TYPE POINT

0 comments on commit 2ac55ea

Please sign in to comment.
You can’t perform that action at this time.