The IDLffShape::SetAttributes procedure method sets the attributes for a specified entity in a Shapefile object.
Obj->[IDLffShape::]SetAttributes, Index, Attribute_Num, Value
or
Obj->[IDLffShape::]SetAttributes, Index, Attributes
The field number for the attribute whose value is being set. This value is 0-based.
An Attribute structure whose fields match the fields in the attribute table. If Attributes is an array, the entities specified in Index, up to the size of the Attributes array, are set. Using this feature, all the attribute values of a set of entities can be set for a Shapefile.
The type of this Attribute structure must match the type that is generated internally for Attribute table. To get a copy of this structure, either get the attribute set for an entity or get the definition using the ATTRIBUTE_STRUCTURE keyword of the IDLffShape::GetProperty method.
A scalar specifying the entity in which you want to set the attributes. The first entity in the Shapefile object is 0.
The value that the attribute is being set to. If the value is not of the correct type, type conversion is attempted.
If Value is an array and Index is a scalar, the value of record is treated as a starting point. Using this feature, all the attribute values of a specific field can be set for a Shapefile.
None
In the following example, we create a new shapefile, define the attributes for the new file, define a new entity, define some attributes, insert the new entity, and then use the SetAttributes method to insert the attributes into the new file:
PRO ex_shapefile_newfile
; Create the new shapefile and define the entity type to Point.
mynewshape=OBJ_NEW('IDLffShape', FILEPATH('cities.shp', $
SUBDIR=['examples', 'data']), /UPDATE, ENTITY_TYPE=1)
; Set the attribute definitions for the new Shapefile.
mynewshape->IDLffShape::AddAttribute, 'CITY_NAME', 7, 25, $
PRECISION=0
mynewshape->IDLffShape::AddAttribute, 'STAT_NAME', 7, 25, $
PRECISION=0
; Create structure for new entity.
entNew = {IDL_SHAPE_ENTITY}
; Define the values for the new entity
entNew.SHAPE_TYPE = 1
entNew.BOUNDS[0] = -104.87270
entNew.BOUNDS[1] = 39.768040
entNew.BOUNDS[2] = 0.00000000
entNew.BOUNDS[3] = 0.00000000
entNew.BOUNDS[4] = -104.87270
entNew.BOUNDS[5] = 39.768040
entNew.BOUNDS[6] = 0.00000000
entNew.BOUNDS[7] = 0.00000000
; Create structure for new attributes.
attrNew = mynewshape->IDLffShape::GetAttributes( $
/ATTRIBUTE_STRUCTURE)
; Define the values for the new attributes.
attrNew.ATTRIBUTE_0 = 'Denver'
attrNew.ATTRIBUTE_1 = 'Colorado'
; Add the new entity to new shapefile.
mynewshape->IDLffShape::PutEntity, entNew
; Add the Colorado attributes to new shapefile.
mynewshape->IDLffShape::SetAttributes, 0, attrNew
; Close the shapefile.
OBJ_DESTROY, mynewshape
END
Introduced: 5.4