# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# ExportOSM.py
# Created on: 2015-02-19 10:15:40.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: ExportOSM <Extent_of_data_download> <Extract_OSM_Tags_into_Standalone_Attributes> <Target_Feature_Dataset> <OSM_Group_Layer> 
# Description: 
# Download OpenStreetMap vector data from the OSM server and load it into a geodatabase. Extract a list of tags and put the values into standalone attributes. As the third step apply predefined symbology to the downloaded data.
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Script arguments
Extent_of_data_download = arcpy.GetParameterAsText(0)

Extract_OSM_Tags_into_Standalone_Attributes = arcpy.GetParameterAsText(1)
if Extract_OSM_Tags_into_Standalone_Attributes == '#' or not Extract_OSM_Tags_into_Standalone_Attributes:
    Extract_OSM_Tags_into_Standalone_Attributes = "false" # provide a default value if unspecified

Target_Feature_Dataset = arcpy.GetParameterAsText(2)

OSM_Group_Layer = arcpy.GetParameterAsText(3)
if OSM_Group_Layer == '#' or not OSM_Group_Layer:
    OSM_Group_Layer = "OSM Group Layer" # provide a default value if unspecified

# Local variables:
OSM_Points = Extent_of_data_download
osm_points = OSM_Points
osm_points_attributes = OSM_Points
OSM_Lines = Extent_of_data_download
osm_lines = OSM_Lines
osm_lines_attributes = OSM_Lines
OSM_Polygons = Extent_of_data_download
osm_polygons = OSM_Polygons
osm_polygons_attributes = OSM_Polygons

# Process: Download OSM Data
arcpy.OSMGPDownload_osmtools("http://www.openstreetmap.org", Extent_of_data_download, "DO_NOT_INCLUDE_REFERENCES", Target_Feature_Dataset, OSM_Points, OSM_Lines, OSM_Polygons)

# Process: OSM Attribute Selector (3)
arcpy.OSMGPAttributeSelector_osmtools(OSM_Points, "ALL")

# Process: Merge Branch Points
arcpy.MergeBranch_management("'c:\\program files (x86)\\arcgis\\desktop10.2\\ArcToolbox\\Toolboxes\\osm.gdb\\xcvb\\xcvb_osm_pt';'c:\\program files (x86)\\arcgis\\desktop10.2\\ArcToolbox\\Toolboxes\\osm.gdb\\xcvb\\xcvb_osm_pt'")

# Process: OSM Attribute Selector
arcpy.OSMGPAttributeSelector_osmtools(OSM_Lines, "ALL")

# Process: Merge Branch Lines
arcpy.MergeBranch_management("'c:\\program files (x86)\\arcgis\\desktop10.2\\ArcToolbox\\Toolboxes\\osm.gdb\\xcvb\\xcvb_osm_ln';'c:\\program files (x86)\\arcgis\\desktop10.2\\ArcToolbox\\Toolboxes\\osm.gdb\\xcvb\\xcvb_osm_ln'")

# Process: OSM Attribute Selector (2)
arcpy.OSMGPAttributeSelector_osmtools(OSM_Polygons, "ALL")

# Process: Merge Branch Polygons
arcpy.MergeBranch_management("'c:\\program files (x86)\\arcgis\\desktop10.2\\ArcToolbox\\Toolboxes\\osm.gdb\\xcvb\\xcvb_osm_ply';'c:\\program files (x86)\\arcgis\\desktop10.2\\ArcToolbox\\Toolboxes\\osm.gdb\\xcvb\\xcvb_osm_ply'")

# Process: Symbolize OSM Data
arcpy.OSMSymbolizer_osmtools(osm_points, osm_lines, osm_polygons, OSM_Group_Layer)

