def test_int(self):
        name = "_int"
        utils.add_field_with_value(self.shapefile, name,
                                   field_value=5)
        nt.assert_true(name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'Integer')
    def test_float(self):
        name = "_float"
        utils.add_field_with_value(self.shapefile, name, field_value=5.0)
        nt.assert_true(
            name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'Double')
    def test_int(self):
        name = "_int"
        utils.add_field_with_value(self.shapefile, name, field_value=5)
        nt.assert_true(
            name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'Integer')
    def test_float(self):
        name = "_float"
        utils.add_field_with_value(self.shapefile, name,
                                   field_value=5.0)
        nt.assert_true(name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'Double')
    def test_no_value_number(self):
        name = "_no_valnum"
        utils.add_field_with_value(self.shapefile, name, field_type='DOUBLE')

        nt.assert_true(
            name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'Double')
    def test_no_value_number(self):
        name = "_no_valnum"
        utils.add_field_with_value(self.shapefile, name,
                                   field_type='DOUBLE')

        nt.assert_true(name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'Double')
    def test_with_general_function(self):
        utils.add_field_with_value(self.shapefile,
                                   self.field_added,
                                   field_type="LONG")
        utils.populate_field(self.shapefile, lambda row: row[0]**2,
                             self.field_added, "FID")

        with arcpy.da.SearchCursor(self.shapefile,
                                   [self.field_added, "FID"]) as cur:
            for row in cur:
                nt.assert_equal(row[0], row[1]**2)
    def test_no_value_string(self):
        name = "_no_valstr"
        utils.add_field_with_value(self.shapefile, name,
                                   field_type='TEXT',
                                   field_length=15)

        nt.assert_true(name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'String')
        nt.assert_true(newfield.length, 15)
    def test_unicode(self):
        name = "_unicode"
        utils.add_field_with_value(self.shapefile, name,
                                   field_value=u"example_value",
                                   field_length=15)

        nt.assert_true(name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'String')
        nt.assert_true(newfield.length, 15)
    def test_with_general_function(self):
        utils.add_field_with_value(self.shapefile, self.field_added, field_type="LONG")
        utils.populate_field(
            self.shapefile,
            lambda row: row[0]**2,
            self.field_added,
            "FID"
        )

        with arcpy.da.SearchCursor(self.shapefile, [self.field_added, "FID"]) as cur:
            for row in cur:
                nt.assert_equal(row[0], row[1] ** 2)
Beispiel #11
0
    def test_unicode(self):
        name = "_unicode"
        utils.add_field_with_value(self.shapefile,
                                   name,
                                   field_value=u"example_value",
                                   field_length=15)

        nt.assert_true(
            name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'String')
        nt.assert_true(newfield.length, 15)
Beispiel #12
0
    def test_no_value_string(self):
        name = "_no_valstr"
        utils.add_field_with_value(self.shapefile,
                                   name,
                                   field_type='TEXT',
                                   field_length=15)

        nt.assert_true(
            name in [f.name for f in arcpy.ListFields(self.shapefile)])

        newfield = arcpy.ListFields(self.shapefile, name)[0]
        nt.assert_equal(newfield.type, u'String')
        nt.assert_true(newfield.length, 15)
Beispiel #13
0
    def test_with_dictionary(self):
        value_dict = {n: n for n in range(7)}
        value_fxn = lambda row: value_dict.get(row[0], -1)
        utils.add_field_with_value(self.shapefile,
                                   self.field_added,
                                   field_type="LONG")

        utils.populate_field(self.shapefile,
                             lambda row: value_dict.get(row[0], -1),
                             self.field_added, "FID")

        with arcpy.da.SearchCursor(self.shapefile,
                                   [self.field_added, "FID"]) as cur:
            for row in cur:
                nt.assert_equal(row[0], row[1])
    def test_with_dictionary(self):
        value_dict = {n: n for n in range(7)}
        value_fxn = lambda row: value_dict.get(row[0], -1)
        utils.add_field_with_value(self.shapefile, self.field_added, field_type="LONG")

        utils.populate_field(
            self.shapefile,
            lambda row: value_dict.get(row[0], -1),
            self.field_added,
            "FID"
        )

        with arcpy.da.SearchCursor(self.shapefile, [self.field_added, "FID"]) as cur:
            for row in cur:
                nt.assert_equal(row[0], row[1])
Beispiel #15
0
    def _add_scenario_columns(layer, elev=None, surge=None, slr=None):
        """ Adds scenario information to a shapefile/layer

        Parameters
        ----------
        layer : str or arcpy.mapping.Layer
            The path to the layer, or the actual layer object that
            will be modified in-place.
        elev, slr : float, optional
            Final elevation and sea level rise associated with the
            scenario.
        surge : str, optional
            The name of the storm surge associated with the scenario
            (e.g., MHHW, 100yr).

        Returns
        -------
        None

        """


        if elev is not None:
            utils.add_field_with_value(
                table=layer,
                field_name="flood_elev",
                field_value=float(elev),
                msg="Adding 'flood_elev' field to ouput",
                verbose=True,
                asMessage=True
            )

        if surge is not None:
            utils.add_field_with_value(
                table=layer,
                field_name="surge",
                field_value=str(surge),
                field_length=10,
                msg="Adding storm surge field to ouput",
                verbose=True,
                asMessage=True
            )

        if slr is not None:
            utils.add_field_with_value(
                table=layer,
                field_name="slr",
                field_value=int(slr),
                msg="Adding sea level rise field to ouput",
                verbose=True,
                asMessage=True
            )
Beispiel #16
0
    def _add_scenario_columns(layer, elev=None, surge=None, slr=None):
        """ Adds scenario information to a shapefile/layer

        Parameters
        ----------
        layer : str or arcpy.mapping.Layer
            The path to the layer, or the actual layer object that
            will be modified in-place.
        elev, slr : float, optional
            Final elevation and sea level rise associated with the
            scenario.
        surge : str, optional
            The name of the storm surge associated with the scenario
            (e.g., MHHW, 100yr).

        Returns
        -------
        None

        """


        if elev is not None:
            utils.add_field_with_value(
                table=layer,
                field_name="flood_elev",
                field_value=float(elev),
                msg="Adding 'flood_elev' field to ouput",
                verbose=True,
                asMessage=True
            )

        if surge is not None:
            utils.add_field_with_value(
                table=layer,
                field_name="surge",
                field_value=str(surge),
                field_length=10,
                msg="Adding storm surge field to ouput",
                verbose=True,
                asMessage=True
            )

        if slr is not None:
            utils.add_field_with_value(
                table=layer,
                field_name="slr",
                field_value=int(slr),
                msg="Adding sea level rise field to ouput",
                verbose=True,
                asMessage=True
            )
Beispiel #17
0
 def test_overwrite_existing_yes(self):
     utils.add_field_with_value(self.shapefile,
                                "existing",
                                overwrite=True,
                                field_type="LONG")
Beispiel #18
0
 def test_overwrite_existing_no(self):
     utils.add_field_with_value(self.shapefile, "existing")
Beispiel #19
0
 def test_no_value_no_field_type(self):
     utils.add_field_with_value(self.shapefile, "_willfail")
 def test_no_value_no_field_type(self):
     utils.add_field_with_value(self.shapefile, "_willfail")
 def test_overwrite_existing_no(self):
     utils.add_field_with_value(self.shapefile, "existing")
 def test_overwrite_existing_yes(self):
     utils.add_field_with_value(self.shapefile, "existing",
                                overwrite=True,
                                field_type="LONG")