<commit_before># coding: utf-8
'''
------------------------------------------------------------------------------
 Copyright 2017 Esri
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
------------------------------------------------------------------------------
 ==================================================
 NumberFeatures_new.py
 --------------------------------------------------
 requirements: ArcGIS X.X, Python 2.7 or Python 3.x
 author: ArcGIS Solutions
 contact: <EMAIL>
 company: Esri
 ==================================================
 description: 
 Number Features Tool logic module. 
 Supports ClearingOperationsTools.pyt
 ==================================================
 history:
 9/6/2017 - mf - original coding/transfer from NumberFeatures.py
 ==================================================
'''


import os, sys, math, traceback
import arcpy
from arcpy import env
from arcpy import sa
import Utilities

class NumberFeatures(object):
    '''
    '''
    def __init__(self):
        '''
        Number Features constructor
        '''
        self.label = "Number Features"
        self.description = "Number input point features within a selected area."

    def getParameterInfo(self):
        '''
        Define parameter definitions
        '''
        input_area_features = arcpy.Parameter(name='input_area_features',
                                              displayName='Input Area to Number',
                                              direction='Input',
                                              datatype='GPFeatureRecordSetLayer',
                                              parameterType='Required',
                                              enabled=True,
                                              multiValue=False)
        input_area_features.value = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                                 "layers", "NumberFeaturesAreaInput.lyr")
        
        input_number_features = arcpy.Parameter(name='input_point_features',
                                               displayName='Features to Number',
                                               direction='Input',
                                               datatype='GPFeatureLayer',
                                               parameterType='Required',
                                               enabled=True,
                                               multiValue=False)

        field_to_number = arcpy.Parameter(name='field_to_number',
                                          displayName='Field to Number',
                                          direction='Input',
                                          datatype='Field',
                                          parameterType='Optional',
                                          enabled=True,
                                          multiValue=False)
        field_to_number.filter.list = ['Short', 'Long', 'Double', 'Single']
        field_to_number.parameterDependencies = [input_number_features.name]
        
        output_features= arcpy.Parameter(name='output_features',
                                         displayName='Output Numbered Features',
                                         direction='Output',
                                         datatype='DEFeatureClass',
                                         parameterType='Optional',
                                         enabled=True,
                                         multiValue=False)
        #output_features.value = r"%scratchGDB%/numbered_features"
        output_features.symbology = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                                 "layers", "NumberedStructures.lyr")
        
        return [input_area_features,
                input_number_features,
                field_to_number,
                output_features]

    def updateParameters(self, parameters):
        '''
        Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed.
        '''
        return

    def updateMessages(self, parameters):
        '''
        '''
        return

    def execute(self, parameters, messages):
        '''
        '''

        output_fc = self.NumberFeatures(parameters[0].value,
                                        parameters[1].value,
                                        parameters[2].value,
                                        parameters[3].value)

        return output_fc


    def NumberFeatures(self,
                       areaToNumber,
                       pointFeatures,
                       numberingField,
                       outputFeatureClass):
        ''' copied and modified from original NumberFeatures.py '''
        g_ESRI_variable_1 = r'%scratchGDB%\tempSortedPoints'
        # areaToNumber = arcpy.GetParameterAsText(0)
        # pointFeatures = arcpy.GetParameterAsText(1)
        # numberingField = arcpy.GetParameterAsText(2)
        # outputFeatureClass = arcpy.GetParameterAsText(3)
        
        arcpy.CopyFeatures_management(areaToNumber, os.path.join("in_memory","areaToNumber"))
        areaToNumber = os.path.join("in_memory","areaToNumber")
        arcpy.AddMessage("outputFeatureClass: {0}".format(outputFeatureClass))

        DEBUG = True
        appEnvironment = None
        mxd, df, aprx, mp, mapList = None, None, None, None, None
        #UPDATE
        # Create a feature layer from the input point features if it is not one already
        #df = arcpy.mapping.ListDataFrames(mxd)[0]

        # pointFeatureName = os.path.basename(pointFeatures) # TypeError: object of type 'geoprocessing Layer object' has no len()
        # pointFeatureName = pointFeatures.name # AttributeError: ValueObject: Get attribute name does not exist
        if pointFeatures:
            pointFeatureName = pointFeatures.name
        else
            pointFeatureName = os.path.basename(pointFeatures)
        
        #arcpy.AddMessage("base path is: " + os.path.basename(pointFeatures))
        layerExists = False

        try:
            # Check that area to number is a polygon
            descArea = arcpy.Describe(areaToNumber)
            areaGeom = descArea.shapeType
            arcpy.AddMessage("Shape type: " + str(areaGeom))
            if (descArea.shapeType != "Polygon"):
                raise Exception("ERROR: The area to number must be a polygon.")

            #Checking the version of the Desktop Application
            gisVersion = arcpy.GetInstallInfo()["Version"]
            # global appEnvironment
            appEnvironment = Utilities.GetApplication()
            if DEBUG == True: arcpy.AddMessage("App environment: " + appEnvironment)

            #Getting the layer name from the Table of Contents
            # global mxd
            # global df
            # global aprx
            # global mp
            # global mapList<commit_msg>Fix syntax error in NumberFeaturesTool.py<commit_after># coding: utf-8
'''
------------------------------------------------------------------------------
 Copyright 2017 Esri
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
------------------------------------------------------------------------------
 ==================================================
 NumberFeatures_new.py
 --------------------------------------------------
 requirements: ArcGIS X.X, Python 2.7 or Python 3.x
 author: <NAME>
 contact: <EMAIL>
 company: Esri
 ==================================================
 description: 
 Number Features Tool logic module. 
 Supports ClearingOperationsTools.pyt
 ==================================================
 history:
 9/6/2017 - mf - original coding/transfer from NumberFeatures.py
 ==================================================
'''


import os, sys, math, traceback
import arcpy
from arcpy import env
from arcpy import sa
import Utilities

class NumberFeatures(object):
    '''
    '''
    def __init__(self):
        '''
        Number Features constructor
        '''
        self.label = "Number Features"
        self.description = "Number input point features within a selected area."

    def getParameterInfo(self):
        '''
        Define parameter definitions
        '''
        input_area_features = arcpy.Parameter(name='input_area_features',
                                              displayName='Input Area to Number',
                                              direction='Input',
                                              datatype='GPFeatureRecordSetLayer',
                                              parameterType='Required',
                                              enabled=True,
                                              multiValue=False)
        input_area_features.value = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                                 "layers", "NumberFeaturesAreaInput.lyr")
        
        input_number_features = arcpy.Parameter(name='input_point_features',
                                               displayName='Features to Number',
                                               direction='Input',
                                               datatype='GPFeatureLayer',
                                               parameterType='Required',
                                               enabled=True,
                                               multiValue=False)

        field_to_number = arcpy.Parameter(name='field_to_number',
                                          displayName='Field to Number',
                                          direction='Input',
                                          datatype='Field',
                                          parameterType='Optional',
                                          enabled=True,
                                          multiValue=False)
        field_to_number.filter.list = ['Short', 'Long', 'Double', 'Single']
        field_to_number.parameterDependencies = [input_number_features.name]
        
        output_features= arcpy.Parameter(name='output_features',
                                         displayName='Output Numbered Features',
                                         direction='Output',
                                         datatype='DEFeatureClass',
                                         parameterType='Optional',
                                         enabled=True,
                                         multiValue=False)
        #output_features.value = r"%scratchGDB%/numbered_features"
        output_features.symbology = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                                 "layers", "NumberedStructures.lyr")
        
        return [input_area_features,
                input_number_features,
                field_to_number,
                output_features]

    def updateParameters(self, parameters):
        '''
        Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed.
        '''
        return

    def updateMessages(self, parameters):
        '''
        '''
        return

    def execute(self, parameters, messages):
        '''
        '''

        output_fc = self.NumberFeatures(parameters[0].value,
                                        parameters[1].value,
                                        parameters[2].value,
                                        parameters[3].value)

        return output_fc


    def NumberFeatures(self,
                       areaToNumber,
                       pointFeatures,
                       numberingField,
                       outputFeatureClass):
        ''' copied and modified from original NumberFeatures.py '''
        g_ESRI_variable_1 = r'%scratchGDB%\tempSortedPoints'
        # areaToNumber = arcpy.GetParameterAsText(0)
        # pointFeatures = arcpy.GetParameterAsText(1)
        # numberingField = arcpy.GetParameterAsText(2)
        # outputFeatureClass = arcpy.GetParameterAsText(3)
        
        arcpy.CopyFeatures_management(areaToNumber, os.path.join("in_memory","areaToNumber"))
        areaToNumber = os.path.join("in_memory","areaToNumber")
        arcpy.AddMessage("outputFeatureClass: {0}".format(outputFeatureClass))

        DEBUG = True
        appEnvironment = None
        mxd, df, aprx, mp, mapList = None, None, None, None, None
        #UPDATE
        # Create a feature layer from the input point features if it is not one already
        #df = arcpy.mapping.ListDataFrames(mxd)[0]

        # pointFeatureName = os.path.basename(pointFeatures) # TypeError: object of type 'geoprocessing Layer object' has no len()
        # pointFeatureName = pointFeatures.name # AttributeError: ValueObject: Get attribute name does not exist
        if pointFeatures:
            pointFeatureName = pointFeatures.name
        else:
            pointFeatureName = os.path.basename(pointFeatures)
        
        #arcpy.AddMessage("base path is: " + os.path.basename(pointFeatures))
        layerExists = False

        try:
            # Check that area to number is a polygon
            descArea = arcpy.Describe(areaToNumber)
            areaGeom = descArea.shapeType
            arcpy.AddMessage("Shape type: " + str(areaGeom))
            if (descArea.shapeType != "Polygon"):
                raise Exception("ERROR: The area to number must be a polygon.")

            #Checking the version of the Desktop Application
            gisVersion = arcpy.GetInstallInfo()["Version"]
            # global appEnvironment
            appEnvironment = Utilities.GetApplication()
            if DEBUG == True: arcpy.AddMessage("App environment: " + appEnvironment)

            #Getting the layer name from the Table of Contents
            # global mxd
            # global df
            # global aprx
            # global mp
            # global mapList
{'fraction_non_alphanumeric': 0.12435991221653256, 'fraction_numerical': 0.003857152357518122, 'mean_word_length': 1.5100984810549156, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 110, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5318660', 'n_tokens_mistral': 3157, 'n_tokens_neox': 3051, 'n_words': 846}