SlideShare a Scribd company logo
1 of 12
# CellCoverage.py
# CreatedbyBPfeiffer3/7/2016
# Programtakesinputs
# 1) a boundaryshapefileforthe region(eg,county,state,region)
# 2) a DEM of the area that mustcover a 24 kilometerbufferof the boundary
# 3) a .csv file of Cell towerlocationswithLattitude,Longitude,andheightof the tower
# 3) a textfile containingastreetname,Lattitude,andLongitudeof watermeters
# 4) thisprogram takesa localRoads.shp,majorRoads.shp,andhighways.shpforreferenceforthe final
map
# Thisprogram calculatesCell receptionbasedontowerlocationsandviewshedanalysis. The outputis
4 gradesof cell
# zonesbasedonviewshed,proximity,andoverlap. Italsooutputs4 shapefilesof watermetersbased
on theircell
# receptionrating. Finally,the programwritesatextsplittingall watermetersintotheir4categories.
importarcpy
fromarcpy.sa import*
arcpy.env.overwriteOutput=True
############# Set up
Function################################################################
def roadsCheck(roadFile,tempfile,outfile,roadName,SpatialReference,boundary):
arcpy.env.overwriteOutput=True
desc = arcpy.Describe(roadFile)
if desc.shapeType =="Polyline":
arcpy.Project_management(roadFile,temp+roadName,spatRef)
arcpy.Clip_analysis(temp+roadName +".shp",gdbFullPath+""+ "boundary",gdbFullPath+""
+ roadName)
else:
print"The shapefileisnota Polyline. Checkyourfile"
#####################################################################################
########
# Setup inputshapefiles.txtfileand.csvfile
CellTowers="C:Usersbrian_000DesktopGIS4080PythonFinal ProjectInFileCellTowers.csv"
DEM = "C:Usersbrian_000DesktopGIS4080PythonFinal ProjectInFileCO_DEM.lyr"
boundary= "C:Usersbrian_000DesktopGIS4080PythonFinal
ProjectInFileBoulderCounty.lyr"
WaterMeters= "C:Usersbrian_000DesktopGIS4080PythonFinal
ProjectInFileWaterMeters.txt"
localRoads= "C:Usersbrian_000DesktopGIS4080 PythonFinal
ProjectInFileLOCAL_ROADS.shp"
majorRoads= "C:Usersbrian_000DesktopGIS4080PythonFinal
ProjectInFileMAJOR_ROADS.shp"
highways= "C:Usersbrian_000DesktopGIS4080PythonFinalProjectInFileHIGHWAYS.shp"
# Setup Folderpaths
temp= "C:Temp"
outFile ="C:Usersbrian_000DesktopGIS4080PythonFinal ProjectOutFile"
# Setup all variables
spatRef = arcpy.SpatialReference(4269)
heightList=[]
streetList=[]
streetList2= []
visibleList=[]
problemList=[]
CTCount= 0
w = 0
x = 0
y = 1
z = 3
p = 0
# Create Geodatatabase andsetpaths
gdbName = "Cell.gdb"
gdbFullPath=outFile +gdbName
try:
if not arcpy.Exists(gdbFullPath):
arcpy.CreateFileGDB_management(outFile,gdbName)
print"Geodatabase Ready"
except:
print"Failedtocreate Geodatabase"
# Error Checkboundaryfile,reproject,andimportintoGeodatabase
desc= arcpy.Describe(boundary)
if desc.shapeType=="Polygon":
arcpy.Project_management(boundary,gdbFullPath+""+ "boundary",spatRef)
desc = arcpy.Describe(gdbFullPath+""+ "boundary")
extentBoundary=desc.Extent
print"boundaryhas beensucessfullyreprojectedandimportedtoGeodatabase"
arcpy.Buffer_analysis(gdbFullPath+""+ "boundary",temp+ "AOI","24 kilometers","FULL")
desc = arcpy.Describe(temp+"AOI"+ ".shp")
extentAOI=desc.Extent
print"AOI hasbeencreated"
else:
print"Boundaryshapefile isnotPolygon"
# Error CheckDEM file,cliptoextentAOI,reproject,andimportintoGeodatabase
desc= arcpy.Describe(DEM)
if desc.datasetType =="RasterDataset":
arcpy.ProjectRaster_management(DEM,temp+ "fullDEM",spatRef)
arcpy.CheckOutExtension("Spatial")
rectExtract = ExtractByRectangle(temp+"fullDEM",extentAOI,"INSIDE")
rectExtract.save(gdbFullPath+""+ "DEM")
print"DEM has beensucessfullyreprojected,clipped,andimportedintoGeodatabase"
arcpy.CheckOutExtension("Spatial")
else:
print"DEM is nota RasterDataset"
# Error CheckCell Towers.csvfile,create Cell Towershapefile
desc= arcpy.Describe(CellTowers)
if desc.DataType == "TextFile":
for fieldindesc.fields:
if field.name =="STREET":
print"STREET fieldexistsinCellTowertextfile"
elif field.name=="LAT":
print"LAT fieldexistsinCellTowertextfile"
elif field.name=="LONG":
print"LONG fieldexistsinCellTowertextfile"
elif field.name=="HEIGHT":
print"HEIGHT fieldexistsinCellTowertextfile"
else:
printfield.name +" fieldinCell Towertextfile isnotneededorincorrect. Tryreformatting.csv
file if problemarises"
try:
arcpy.CreateFeatureclass_management(temp,"CTtemp","POINT","","","", spatRef)
arcpy.AddField_management(temp+"CTtemp.shp","NAME","TEXT")
arcpy.AddField_management(temp+"CTtemp.shp","HEIGHT","DOUBLE")
print"Cell Towers shapefile hasbeencreatedandfieldshave beenadded"
except:
print"Failedtocreate Cell Towersshapefile"
# Write geometryforCell Towers.csv,clipCell TowerstoAOI,reproject,anduploadshapefile to
Geodatabase
try:
cursor= arcpy.da.SearchCursor(CellTowers,["STREET","LONG","LAT","HEIGHT"])
cursor2 = arcpy.da.InsertCursor(temp+"CTtemp.shp",["SHAPE@"])
forrow incursor:
streetList.append(row[0])
heightList.append(row[3])
pointlist=arcpy.Array()
point= arcpy.Point(row[1],row[2])
pointlist.add(point)
cursor2.insertRow(pointlist)
del cursor
del cursor2
print"SucessfulywortegeometryforCell Towers"
except:
print"Failedtowrite geometry"
try:
cursor= arcpy.da.UpdateCursor(temp+"CTtemp.shp",["NAME","HEIGHT"])
forrow incursor:
row[0] = streetList[x]
row[1] = heightList[x]
cursor.updateRow(row)
x = x + 1
print"Cell TowerShapefilehasbeenupdated"
except:
print"Failedtoupdate Cell Towershapefile"
del cursor
try:
arcpy.MakeFeatureLayer_management(temp+"CTtemp.shp","CTtempLyr")
arcpy.SelectLayerByLocation_management("CTtempLyr","WITHIN",temp+"AOI.shp","",
"NEW_SELECTION")
CTCount= int(arcpy.GetCount_management("CTtempLyr").getOutput(0))
except:
print"FailedtoclipCell Towerpointstoboundary"
if CTCount > 0:
try:
arcpy.Project_management("CTtempLyr",gdbFullPath+""+ "CT" , spatRef)
print"Projectionhassucceededand"+ str(Count) + " Cell Towerlacationshave beenuploadedto
Geodatabase"
except:
print"FailedtoreprojectCell Towershapefile"
else:
print"Cell Tower.csvis nota textfile orismissingdata. Checkfile forerrors"
# errorcheck WaterMeters .txt,write geometry,andupdate name field
desc= arcpy.Describe(WaterMeters)
if desc.DataType == "TextFile":
try:
arcpy.CreateFeatureclass_management(temp,"WMtemp","POINT","","", "",spatRef)
arcpy.AddField_management(temp+"WMtemp.shp","NAME","TEXT")
print"WaterMeters shapefile hasbeencreatedandfieldshave beenadded"
except:
print"Failedtocreate WaterMeters shapefile"
try:
txt= open(WaterMeters)
cursor= arcpy.da.InsertCursor(temp+"WMtemp.shp","SHAPE@")
forline intxt:
lineseg=line.split(",")
if str(lineseg[1][0]) =="-"and len(lineseg[2]) >12 and lineseg[0] !="":
streetList2.append(lineseg[0])
pointlist2=arcpy.Array()
point= arcpy.Point(lineseg[1], lineseg[2])
pointlist2.add(point)
cursor.insertRow(pointlist2)
else:
problem= lineseg[0] +", " + lineseg[1] +"," + lineseg[2]
problemList.append(problem)
del cursor
txt.close()
if len(problemList) >0:
print"!!!THE FOLLOWINGLINES CONTAIN ERRORS!!!"
printproblemList
else:
print"Noerrors detectedinWaterMeterlist"
except:
print"Failedtowrite geometryforWaterMeters"
try:
cursor= arcpy.da.UpdateCursor(temp+"WMtemp.shp",["NAME"])
forrow incursor:
row[0] = streetList2[w]
cursor.updateRow(row)
w = w + 1
del cursor
print"WaterMeter shapefile hasbeenupdated"
except:
print"Failedtoupdate WaterMetershapefile"
#Checkthat Water Meterpointsare withinAOIandloadshapefile intoGeodatabase
try:
arcpy.MakeFeatureLayer_management(temp+"WMtemp.shp","WMLyr")
arcpy.SelectLayerByLocation_management("WMLyr","WITHIN",gdbFullPath+""+ "boundary",
"", "NEW_SELECTION")
Count= int(arcpy.GetCount_management("WMLyr").getOutput(0))
except:
print"FailedtoclipWaterMeter pointstoboundary"
if Count > 0:
try:
arcpy.Project_management("WMLyr",gdbFullPath+""+ "WM" , spatRef)
print"Projectionhassucceededand"+ str(Count) + " Water Meterlacationshave beenuploaded
to Geodatabase"
except:
print"FailedtoreprojectWaterMetershapefile"
else:
print"Water Meter .txtisnot a textfile orismissingdata. Checkfile forerrors"
# use functiontoerror checkroads,reproject,clip toboundary,anduploadto Geodatabase
try:
roadsCheck(localRoads,temp,gdbFullPath+"","localRoads",spatRef,gdbFullPath+""+
"boundary")
roadsCheck(majorRoads,temp,gdbFullPath+"","majorRoads",spatRef,gdbFullPath+""+
"boundary")
roadsCheck(highways,temp,gdbFullPath+"","highways",spatRef,gdbFullPath+""+
"boundary")
print"Roads and Highwayshave beenreprojectedandimportedtoGeodatabase"
except:
print"FailedtouploadRoadsand Highways"
CTName = "CT"
CT = gdbFullPath+""+ CTName
inRast= gdbFullPath+""+ "DEM"
# Setvariablesforviewanalysis
CTLyr = temp+ CTName
Ring= CTLyr + "Ring"
Polygon= temp+ CTName + "Vispoly"
PolyBuff =Polygon+ "Buff"
Visible=temp+ "Visible"
# CheckoutSpatial extension
try:
if arcpy.CheckExtension("Spatial") =="Available":
arcpy.CheckOutExtension("Spatial")
print"Spatial extensioncheckedout"
except:
raise LicenseError
# SelecteachCell Tower,create view analysis,create polygon,bufferpolygon,cliptoringsbuffer,
update value field
while True:
try:
arcpy.MakeFeatureLayer_management(CT,"CTLyr")
arcpy.SelectLayerByAttribute_management("CTLyr","NEW_SELECTION",'"OBJECTID"=' + str(y))
arcpy.MultipleRingBuffer_analysis("CTLyr",Ring+str(y),[8,16, 24], "kilometers","","ALL")
Vis= arcpy.sa.Visibility(inRast,"CTLyr","","","NODATA","","", "", "","", "HEIGHT")
Vis.save(Visible+str(y))
arcpy.RasterToPolygon_conversion(Visible +str(y),Polygon+str(y),"SIMPLIFY","VALUE")
poly= CTName.lower()
arcpy.MakeFeatureLayer_management(temp+poly+ "vispoly"+str(y) + ".shp",Polygon+str(y) +
"lyr")
arcpy.SelectLayerByAttribute_management(Polygon+str(y) + "lyr","NEW_SELECTION",
'"GRIDCODE" = 1')
arcpy.Buffer_analysis(Polygon+str(y) + "lyr",PolyBuff +str(y),"200 meters","","","ALL")
arcpy.Clip_analysis(Ring+str(y) +".shp",PolyBuff+str(y) + ".shp",Visible +str(y))
visibleList.append(Visible +str(y) + ".shp")
arcpy.AddField_management(Visible +str(y) + ".shp","VALUE","SHORT")
cursor= arcpy.da.UpdateCursor( Visible +str(y) +".shp",["VALUE"])
visibleList.append(Visible +str(y) + ".shp")
forrow incursor:
row[0] = z
cursor.updateRow(row)
z = z -1
print"Visible"+str(y) + " has beensucessfullycreated"
y= y + 1
del cursor
except:
print"Failedtocreate all visiblelayers"
else:
print"Error withData. Cell Towersmaynotfall withinAOI"
arcpy.CheckInExtension("Spatial")
# Setup variablesforunionandfinal shapefiles
BR = "Bad_Reception"
GoodR = "Good_Reception"
VGR = "VeryGood_Reception"
GR = "Great_Reception"
BRLyr = "BRLyr"
UnionLyr= "UnionLyr"
union= temp+ "UnionAll"
try:
arcpy.Union_analysis(visibleList,union)
arcpy.Clip_analysis(union+".shp",gdbFullPath+""+ "boundary",union+"_clip.shp")
arcpy.MakeFeatureLayer_management(union+"_clip.shp",UnionLyr)
arcpy.Erase_analysis(gdbFullPath+"" + "boundary",union+"_clip.shp",gdbFullPath+""+ BR)
arcpy.MakeFeatureLayer_management(temp+"Bad_Reception.shp",BRLyr)
arcpy.SelectLayerByAttribute_management("UnionLyr","NEW_SELECTION",'"VALUE"= 0')
arcpy.Dissolve_management("UnionLyr",gdbFullPath+""+ GoodR)
arcpy.SelectLayerByAttribute_management("UnionLyr","NEW_SELECTION",'"VALUE"= 1')
arcpy.Dissolve_management("UnionLyr",gdbFullPath+""+ VGR)
arcpy.SelectLayerByAttribute_management("UnionLyr","NEW_SELECTION",'"VALUE"> 1')
arcpy.Dissolve_management("UnionLyr",gdbFullPath+""+ GR)
print"Union shapefile hasbeencreatedanduploaded intoGeodatabase"
except:
print"Failedtocreate Union shapefile"
# Write an outputfile "WaterMeterList.txt"thatlistseachwatermeterbycategory
try:
WMtxt = open(outFile+"WaterMeterList.txt","w")
WMtxt.write("WaterMeterListbyVerizonCell ReceptionnnBadorNoCell Receptionn")
cursor = arcpy.da.SearchCursor(gdbFullPath+""+ "WM_" + BR, ["NAME"])
for row incursor:
WMtxt.write(row[0] +"n")
del cursor
WMtxt.write("nGoodCell Receptionn")
cursor = arcpy.da.SearchCursor(gdbFullPath+""+ "WM_" + GoodR,["NAME"])
for row incursor:
WMtxt.write(row[0] +"n")
del cursor
WMtxt.write("nVeryGoodCell Receptionn")
cursor = arcpy.da.SearchCursor(gdbFullPath+""+ "WM_" + VGR,["NAME"])
for row incursor:
WMtxt.write(row[0] +"n")
del cursor
WMtxt.write("nGreatCell Receptionn")
cursor = arcpy.da.SearchCursor(gdbFullPath+""+ "WM_" + GR, ["NAME"])
for row incursor:
WMtxt.write(row[0] +"n")
del cursor
WMtxt.close()
print"WaterMeterList.txtwassucessfullycreatedandwritten"
except:
print"Failedtocreate WaterMeterList.txt"
print"!!!!!!!!!!!!!Programhasfinishedrunning!!!!!!!!!!!!!!!!!!!!!"

More Related Content

What's hot

A Fast and Efficient Time Series Storage Based on Apache Solr
A Fast and Efficient Time Series Storage Based on Apache SolrA Fast and Efficient Time Series Storage Based on Apache Solr
A Fast and Efficient Time Series Storage Based on Apache SolrQAware GmbH
 
6.3.2 CLIMADA model demo
6.3.2 CLIMADA model demo6.3.2 CLIMADA model demo
6.3.2 CLIMADA model demoNAP Events
 
Excerpts from Spatial Data Analysis using R and QGIS
Excerpts from Spatial Data Analysis using R and QGISExcerpts from Spatial Data Analysis using R and QGIS
Excerpts from Spatial Data Analysis using R and QGISDr. Subhash Chandra Ghosh
 
Probabilistic data structures. Part 2. Cardinality
Probabilistic data structures. Part 2. CardinalityProbabilistic data structures. Part 2. Cardinality
Probabilistic data structures. Part 2. CardinalityAndrii Gakhov
 
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...Data Con LA
 
Case Based Planner Platform For Rts Games
Case Based Planner Platform For Rts GamesCase Based Planner Platform For Rts Games
Case Based Planner Platform For Rts GamesAbdelrahman Al-Ogail
 
HyperLogLog in Hive - How to count sheep efficiently?
HyperLogLog in Hive - How to count sheep efficiently?HyperLogLog in Hive - How to count sheep efficiently?
HyperLogLog in Hive - How to count sheep efficiently?bzamecnik
 

What's hot (8)

A Fast and Efficient Time Series Storage Based on Apache Solr
A Fast and Efficient Time Series Storage Based on Apache SolrA Fast and Efficient Time Series Storage Based on Apache Solr
A Fast and Efficient Time Series Storage Based on Apache Solr
 
6.3.2 CLIMADA model demo
6.3.2 CLIMADA model demo6.3.2 CLIMADA model demo
6.3.2 CLIMADA model demo
 
Excerpts from Spatial Data Analysis using R and QGIS
Excerpts from Spatial Data Analysis using R and QGISExcerpts from Spatial Data Analysis using R and QGIS
Excerpts from Spatial Data Analysis using R and QGIS
 
Probabilistic data structures. Part 2. Cardinality
Probabilistic data structures. Part 2. CardinalityProbabilistic data structures. Part 2. Cardinality
Probabilistic data structures. Part 2. Cardinality
 
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...
 
Case Based Planner Platform For Rts Games
Case Based Planner Platform For Rts GamesCase Based Planner Platform For Rts Games
Case Based Planner Platform For Rts Games
 
SAADATMAND_PYTHON
SAADATMAND_PYTHONSAADATMAND_PYTHON
SAADATMAND_PYTHON
 
HyperLogLog in Hive - How to count sheep efficiently?
HyperLogLog in Hive - How to count sheep efficiently?HyperLogLog in Hive - How to count sheep efficiently?
HyperLogLog in Hive - How to count sheep efficiently?
 

Viewers also liked

Dido Green: Expectations for Therapy and Relationship to Confidence and Compe...
Dido Green: Expectations for Therapy and Relationship to Confidence and Compe...Dido Green: Expectations for Therapy and Relationship to Confidence and Compe...
Dido Green: Expectations for Therapy and Relationship to Confidence and Compe...Beitissie1
 
IMTC Miami Conference - Social Media and Remittances - Michael Kent
IMTC Miami Conference - Social Media and Remittances - Michael KentIMTC Miami Conference - Social Media and Remittances - Michael Kent
IMTC Miami Conference - Social Media and Remittances - Michael KentMichael Kent
 
SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013Connor McDonald
 
87229 RBH Journal Langridge v5
87229 RBH Journal Langridge v587229 RBH Journal Langridge v5
87229 RBH Journal Langridge v5Phil Langridge
 
The potential of Genetically Modified Crops in the United Kingdom.
The potential of Genetically Modified Crops in the United Kingdom.The potential of Genetically Modified Crops in the United Kingdom.
The potential of Genetically Modified Crops in the United Kingdom.Lucille Gilpin
 
Barrior free built environment
Barrior free built environmentBarrior free built environment
Barrior free built environmentAr.Muhammad Riyas
 

Viewers also liked (12)

Dido Green: Expectations for Therapy and Relationship to Confidence and Compe...
Dido Green: Expectations for Therapy and Relationship to Confidence and Compe...Dido Green: Expectations for Therapy and Relationship to Confidence and Compe...
Dido Green: Expectations for Therapy and Relationship to Confidence and Compe...
 
IMTC Miami Conference - Social Media and Remittances - Michael Kent
IMTC Miami Conference - Social Media and Remittances - Michael KentIMTC Miami Conference - Social Media and Remittances - Michael Kent
IMTC Miami Conference - Social Media and Remittances - Michael Kent
 
Marketing and PR in Times of Turmoil
Marketing and PR in Times of TurmoilMarketing and PR in Times of Turmoil
Marketing and PR in Times of Turmoil
 
Apresentacao
ApresentacaoApresentacao
Apresentacao
 
SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013
 
Optimizer Statistics
Optimizer StatisticsOptimizer Statistics
Optimizer Statistics
 
USGS
USGSUSGS
USGS
 
Presentation1
Presentation1Presentation1
Presentation1
 
87229 RBH Journal Langridge v5
87229 RBH Journal Langridge v587229 RBH Journal Langridge v5
87229 RBH Journal Langridge v5
 
FBWCA Memo Presentation
FBWCA Memo PresentationFBWCA Memo Presentation
FBWCA Memo Presentation
 
The potential of Genetically Modified Crops in the United Kingdom.
The potential of Genetically Modified Crops in the United Kingdom.The potential of Genetically Modified Crops in the United Kingdom.
The potential of Genetically Modified Crops in the United Kingdom.
 
Barrior free built environment
Barrior free built environmentBarrior free built environment
Barrior free built environment
 

Similar to CellCoverage

Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixInfluxData
 
JDD2015: On-heap cache vs Off-heap cache - Radek Grębski
JDD2015: On-heap cache vs Off-heap cache - Radek GrębskiJDD2015: On-heap cache vs Off-heap cache - Radek Grębski
JDD2015: On-heap cache vs Off-heap cache - Radek GrębskiPROIDEA
 
On heap cache vs off-heap cache
On heap cache vs off-heap cacheOn heap cache vs off-heap cache
On heap cache vs off-heap cachergrebski
 
Robust Operations of Kafka Streams
Robust Operations of Kafka StreamsRobust Operations of Kafka Streams
Robust Operations of Kafka Streamsconfluent
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopSages
 
TinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on SessionTinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on SessionRazvan Musaloiu-E.
 
Machine Learning and Go. Go!
Machine Learning and Go. Go!Machine Learning and Go. Go!
Machine Learning and Go. Go!Diana Ortega
 
Real-Time Big Data with Storm, Kafka and GigaSpaces
Real-Time Big Data with Storm, Kafka and GigaSpacesReal-Time Big Data with Storm, Kafka and GigaSpaces
Real-Time Big Data with Storm, Kafka and GigaSpacesOleksii Diagiliev
 
100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects 100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects Andrey Karpov
 
Practical data science_public
Practical data science_publicPractical data science_public
Practical data science_publicLong Nguyen
 
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...David Walker
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321Teddy Hsiung
 
Polymer Brush Data Processor
Polymer Brush Data ProcessorPolymer Brush Data Processor
Polymer Brush Data ProcessorCory Bethrant
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manualVivek Kumar Sinha
 

Similar to CellCoverage (20)

Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
 
R and cpp
R and cppR and cpp
R and cpp
 
JDD2015: On-heap cache vs Off-heap cache - Radek Grębski
JDD2015: On-heap cache vs Off-heap cache - Radek GrębskiJDD2015: On-heap cache vs Off-heap cache - Radek Grębski
JDD2015: On-heap cache vs Off-heap cache - Radek Grębski
 
On heap cache vs off-heap cache
On heap cache vs off-heap cacheOn heap cache vs off-heap cache
On heap cache vs off-heap cache
 
Robust Operations of Kafka Streams
Robust Operations of Kafka StreamsRobust Operations of Kafka Streams
Robust Operations of Kafka Streams
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache Hadoop
 
TinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on SessionTinyOS 2.1 Tutorial: Hands-on Session
TinyOS 2.1 Tutorial: Hands-on Session
 
Klee and angr
Klee and angrKlee and angr
Klee and angr
 
Java 8 monads
Java 8   monadsJava 8   monads
Java 8 monads
 
Machine Learning and Go. Go!
Machine Learning and Go. Go!Machine Learning and Go. Go!
Machine Learning and Go. Go!
 
How to Make Hand Detector on Native Activity with OpenCV
How to Make Hand Detector on Native Activity with OpenCVHow to Make Hand Detector on Native Activity with OpenCV
How to Make Hand Detector on Native Activity with OpenCV
 
Real-Time Big Data with Storm, Kafka and GigaSpaces
Real-Time Big Data with Storm, Kafka and GigaSpacesReal-Time Big Data with Storm, Kafka and GigaSpaces
Real-Time Big Data with Storm, Kafka and GigaSpaces
 
100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects 100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects
 
Practical data science_public
Practical data science_publicPractical data science_public
Practical data science_public
 
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
 
R and C++
R and C++R and C++
R and C++
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
 
Polymer Brush Data Processor
Polymer Brush Data ProcessorPolymer Brush Data Processor
Polymer Brush Data Processor
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
 
The Future of Apache Storm
The Future of Apache StormThe Future of Apache Storm
The Future of Apache Storm
 

CellCoverage

  • 1. # CellCoverage.py # CreatedbyBPfeiffer3/7/2016 # Programtakesinputs # 1) a boundaryshapefileforthe region(eg,county,state,region) # 2) a DEM of the area that mustcover a 24 kilometerbufferof the boundary # 3) a .csv file of Cell towerlocationswithLattitude,Longitude,andheightof the tower # 3) a textfile containingastreetname,Lattitude,andLongitudeof watermeters # 4) thisprogram takesa localRoads.shp,majorRoads.shp,andhighways.shpforreferenceforthe final map # Thisprogram calculatesCell receptionbasedontowerlocationsandviewshedanalysis. The outputis 4 gradesof cell # zonesbasedonviewshed,proximity,andoverlap. Italsooutputs4 shapefilesof watermetersbased on theircell # receptionrating. Finally,the programwritesatextsplittingall watermetersintotheir4categories. importarcpy fromarcpy.sa import* arcpy.env.overwriteOutput=True ############# Set up Function################################################################ def roadsCheck(roadFile,tempfile,outfile,roadName,SpatialReference,boundary): arcpy.env.overwriteOutput=True desc = arcpy.Describe(roadFile) if desc.shapeType =="Polyline": arcpy.Project_management(roadFile,temp+roadName,spatRef) arcpy.Clip_analysis(temp+roadName +".shp",gdbFullPath+""+ "boundary",gdbFullPath+"" + roadName) else: print"The shapefileisnota Polyline. Checkyourfile" ##################################################################################### ########
  • 2. # Setup inputshapefiles.txtfileand.csvfile CellTowers="C:Usersbrian_000DesktopGIS4080PythonFinal ProjectInFileCellTowers.csv" DEM = "C:Usersbrian_000DesktopGIS4080PythonFinal ProjectInFileCO_DEM.lyr" boundary= "C:Usersbrian_000DesktopGIS4080PythonFinal ProjectInFileBoulderCounty.lyr" WaterMeters= "C:Usersbrian_000DesktopGIS4080PythonFinal ProjectInFileWaterMeters.txt" localRoads= "C:Usersbrian_000DesktopGIS4080 PythonFinal ProjectInFileLOCAL_ROADS.shp" majorRoads= "C:Usersbrian_000DesktopGIS4080PythonFinal ProjectInFileMAJOR_ROADS.shp" highways= "C:Usersbrian_000DesktopGIS4080PythonFinalProjectInFileHIGHWAYS.shp" # Setup Folderpaths temp= "C:Temp" outFile ="C:Usersbrian_000DesktopGIS4080PythonFinal ProjectOutFile" # Setup all variables spatRef = arcpy.SpatialReference(4269) heightList=[] streetList=[] streetList2= [] visibleList=[] problemList=[] CTCount= 0 w = 0 x = 0 y = 1 z = 3 p = 0
  • 3. # Create Geodatatabase andsetpaths gdbName = "Cell.gdb" gdbFullPath=outFile +gdbName try: if not arcpy.Exists(gdbFullPath): arcpy.CreateFileGDB_management(outFile,gdbName) print"Geodatabase Ready" except: print"Failedtocreate Geodatabase" # Error Checkboundaryfile,reproject,andimportintoGeodatabase desc= arcpy.Describe(boundary) if desc.shapeType=="Polygon": arcpy.Project_management(boundary,gdbFullPath+""+ "boundary",spatRef) desc = arcpy.Describe(gdbFullPath+""+ "boundary") extentBoundary=desc.Extent print"boundaryhas beensucessfullyreprojectedandimportedtoGeodatabase" arcpy.Buffer_analysis(gdbFullPath+""+ "boundary",temp+ "AOI","24 kilometers","FULL") desc = arcpy.Describe(temp+"AOI"+ ".shp") extentAOI=desc.Extent print"AOI hasbeencreated" else: print"Boundaryshapefile isnotPolygon" # Error CheckDEM file,cliptoextentAOI,reproject,andimportintoGeodatabase desc= arcpy.Describe(DEM) if desc.datasetType =="RasterDataset": arcpy.ProjectRaster_management(DEM,temp+ "fullDEM",spatRef) arcpy.CheckOutExtension("Spatial") rectExtract = ExtractByRectangle(temp+"fullDEM",extentAOI,"INSIDE")
  • 4. rectExtract.save(gdbFullPath+""+ "DEM") print"DEM has beensucessfullyreprojected,clipped,andimportedintoGeodatabase" arcpy.CheckOutExtension("Spatial") else: print"DEM is nota RasterDataset" # Error CheckCell Towers.csvfile,create Cell Towershapefile desc= arcpy.Describe(CellTowers) if desc.DataType == "TextFile": for fieldindesc.fields: if field.name =="STREET": print"STREET fieldexistsinCellTowertextfile" elif field.name=="LAT": print"LAT fieldexistsinCellTowertextfile" elif field.name=="LONG": print"LONG fieldexistsinCellTowertextfile" elif field.name=="HEIGHT": print"HEIGHT fieldexistsinCellTowertextfile" else: printfield.name +" fieldinCell Towertextfile isnotneededorincorrect. Tryreformatting.csv file if problemarises" try: arcpy.CreateFeatureclass_management(temp,"CTtemp","POINT","","","", spatRef) arcpy.AddField_management(temp+"CTtemp.shp","NAME","TEXT") arcpy.AddField_management(temp+"CTtemp.shp","HEIGHT","DOUBLE") print"Cell Towers shapefile hasbeencreatedandfieldshave beenadded" except: print"Failedtocreate Cell Towersshapefile"
  • 5. # Write geometryforCell Towers.csv,clipCell TowerstoAOI,reproject,anduploadshapefile to Geodatabase try: cursor= arcpy.da.SearchCursor(CellTowers,["STREET","LONG","LAT","HEIGHT"]) cursor2 = arcpy.da.InsertCursor(temp+"CTtemp.shp",["SHAPE@"]) forrow incursor: streetList.append(row[0]) heightList.append(row[3]) pointlist=arcpy.Array() point= arcpy.Point(row[1],row[2]) pointlist.add(point) cursor2.insertRow(pointlist) del cursor del cursor2 print"SucessfulywortegeometryforCell Towers" except: print"Failedtowrite geometry" try: cursor= arcpy.da.UpdateCursor(temp+"CTtemp.shp",["NAME","HEIGHT"]) forrow incursor: row[0] = streetList[x] row[1] = heightList[x] cursor.updateRow(row) x = x + 1 print"Cell TowerShapefilehasbeenupdated" except: print"Failedtoupdate Cell Towershapefile" del cursor try:
  • 6. arcpy.MakeFeatureLayer_management(temp+"CTtemp.shp","CTtempLyr") arcpy.SelectLayerByLocation_management("CTtempLyr","WITHIN",temp+"AOI.shp","", "NEW_SELECTION") CTCount= int(arcpy.GetCount_management("CTtempLyr").getOutput(0)) except: print"FailedtoclipCell Towerpointstoboundary" if CTCount > 0: try: arcpy.Project_management("CTtempLyr",gdbFullPath+""+ "CT" , spatRef) print"Projectionhassucceededand"+ str(Count) + " Cell Towerlacationshave beenuploadedto Geodatabase" except: print"FailedtoreprojectCell Towershapefile" else: print"Cell Tower.csvis nota textfile orismissingdata. Checkfile forerrors" # errorcheck WaterMeters .txt,write geometry,andupdate name field desc= arcpy.Describe(WaterMeters) if desc.DataType == "TextFile": try: arcpy.CreateFeatureclass_management(temp,"WMtemp","POINT","","", "",spatRef) arcpy.AddField_management(temp+"WMtemp.shp","NAME","TEXT") print"WaterMeters shapefile hasbeencreatedandfieldshave beenadded" except: print"Failedtocreate WaterMeters shapefile" try: txt= open(WaterMeters) cursor= arcpy.da.InsertCursor(temp+"WMtemp.shp","SHAPE@") forline intxt: lineseg=line.split(",")
  • 7. if str(lineseg[1][0]) =="-"and len(lineseg[2]) >12 and lineseg[0] !="": streetList2.append(lineseg[0]) pointlist2=arcpy.Array() point= arcpy.Point(lineseg[1], lineseg[2]) pointlist2.add(point) cursor.insertRow(pointlist2) else: problem= lineseg[0] +", " + lineseg[1] +"," + lineseg[2] problemList.append(problem) del cursor txt.close() if len(problemList) >0: print"!!!THE FOLLOWINGLINES CONTAIN ERRORS!!!" printproblemList else: print"Noerrors detectedinWaterMeterlist" except: print"Failedtowrite geometryforWaterMeters" try: cursor= arcpy.da.UpdateCursor(temp+"WMtemp.shp",["NAME"]) forrow incursor: row[0] = streetList2[w] cursor.updateRow(row) w = w + 1 del cursor print"WaterMeter shapefile hasbeenupdated" except: print"Failedtoupdate WaterMetershapefile" #Checkthat Water Meterpointsare withinAOIandloadshapefile intoGeodatabase
  • 8. try: arcpy.MakeFeatureLayer_management(temp+"WMtemp.shp","WMLyr") arcpy.SelectLayerByLocation_management("WMLyr","WITHIN",gdbFullPath+""+ "boundary", "", "NEW_SELECTION") Count= int(arcpy.GetCount_management("WMLyr").getOutput(0)) except: print"FailedtoclipWaterMeter pointstoboundary" if Count > 0: try: arcpy.Project_management("WMLyr",gdbFullPath+""+ "WM" , spatRef) print"Projectionhassucceededand"+ str(Count) + " Water Meterlacationshave beenuploaded to Geodatabase" except: print"FailedtoreprojectWaterMetershapefile" else: print"Water Meter .txtisnot a textfile orismissingdata. Checkfile forerrors" # use functiontoerror checkroads,reproject,clip toboundary,anduploadto Geodatabase try: roadsCheck(localRoads,temp,gdbFullPath+"","localRoads",spatRef,gdbFullPath+""+ "boundary") roadsCheck(majorRoads,temp,gdbFullPath+"","majorRoads",spatRef,gdbFullPath+""+ "boundary") roadsCheck(highways,temp,gdbFullPath+"","highways",spatRef,gdbFullPath+""+ "boundary") print"Roads and Highwayshave beenreprojectedandimportedtoGeodatabase" except: print"FailedtouploadRoadsand Highways" CTName = "CT"
  • 9. CT = gdbFullPath+""+ CTName inRast= gdbFullPath+""+ "DEM" # Setvariablesforviewanalysis CTLyr = temp+ CTName Ring= CTLyr + "Ring" Polygon= temp+ CTName + "Vispoly" PolyBuff =Polygon+ "Buff" Visible=temp+ "Visible" # CheckoutSpatial extension try: if arcpy.CheckExtension("Spatial") =="Available": arcpy.CheckOutExtension("Spatial") print"Spatial extensioncheckedout" except: raise LicenseError # SelecteachCell Tower,create view analysis,create polygon,bufferpolygon,cliptoringsbuffer, update value field while True: try: arcpy.MakeFeatureLayer_management(CT,"CTLyr") arcpy.SelectLayerByAttribute_management("CTLyr","NEW_SELECTION",'"OBJECTID"=' + str(y)) arcpy.MultipleRingBuffer_analysis("CTLyr",Ring+str(y),[8,16, 24], "kilometers","","ALL") Vis= arcpy.sa.Visibility(inRast,"CTLyr","","","NODATA","","", "", "","", "HEIGHT") Vis.save(Visible+str(y)) arcpy.RasterToPolygon_conversion(Visible +str(y),Polygon+str(y),"SIMPLIFY","VALUE") poly= CTName.lower() arcpy.MakeFeatureLayer_management(temp+poly+ "vispoly"+str(y) + ".shp",Polygon+str(y) + "lyr") arcpy.SelectLayerByAttribute_management(Polygon+str(y) + "lyr","NEW_SELECTION", '"GRIDCODE" = 1')
  • 10. arcpy.Buffer_analysis(Polygon+str(y) + "lyr",PolyBuff +str(y),"200 meters","","","ALL") arcpy.Clip_analysis(Ring+str(y) +".shp",PolyBuff+str(y) + ".shp",Visible +str(y)) visibleList.append(Visible +str(y) + ".shp") arcpy.AddField_management(Visible +str(y) + ".shp","VALUE","SHORT") cursor= arcpy.da.UpdateCursor( Visible +str(y) +".shp",["VALUE"]) visibleList.append(Visible +str(y) + ".shp") forrow incursor: row[0] = z cursor.updateRow(row) z = z -1 print"Visible"+str(y) + " has beensucessfullycreated" y= y + 1 del cursor except: print"Failedtocreate all visiblelayers" else: print"Error withData. Cell Towersmaynotfall withinAOI" arcpy.CheckInExtension("Spatial") # Setup variablesforunionandfinal shapefiles BR = "Bad_Reception" GoodR = "Good_Reception" VGR = "VeryGood_Reception" GR = "Great_Reception" BRLyr = "BRLyr" UnionLyr= "UnionLyr" union= temp+ "UnionAll" try: arcpy.Union_analysis(visibleList,union)
  • 11. arcpy.Clip_analysis(union+".shp",gdbFullPath+""+ "boundary",union+"_clip.shp") arcpy.MakeFeatureLayer_management(union+"_clip.shp",UnionLyr) arcpy.Erase_analysis(gdbFullPath+"" + "boundary",union+"_clip.shp",gdbFullPath+""+ BR) arcpy.MakeFeatureLayer_management(temp+"Bad_Reception.shp",BRLyr) arcpy.SelectLayerByAttribute_management("UnionLyr","NEW_SELECTION",'"VALUE"= 0') arcpy.Dissolve_management("UnionLyr",gdbFullPath+""+ GoodR) arcpy.SelectLayerByAttribute_management("UnionLyr","NEW_SELECTION",'"VALUE"= 1') arcpy.Dissolve_management("UnionLyr",gdbFullPath+""+ VGR) arcpy.SelectLayerByAttribute_management("UnionLyr","NEW_SELECTION",'"VALUE"> 1') arcpy.Dissolve_management("UnionLyr",gdbFullPath+""+ GR) print"Union shapefile hasbeencreatedanduploaded intoGeodatabase" except: print"Failedtocreate Union shapefile" # Write an outputfile "WaterMeterList.txt"thatlistseachwatermeterbycategory try: WMtxt = open(outFile+"WaterMeterList.txt","w") WMtxt.write("WaterMeterListbyVerizonCell ReceptionnnBadorNoCell Receptionn") cursor = arcpy.da.SearchCursor(gdbFullPath+""+ "WM_" + BR, ["NAME"]) for row incursor: WMtxt.write(row[0] +"n") del cursor WMtxt.write("nGoodCell Receptionn") cursor = arcpy.da.SearchCursor(gdbFullPath+""+ "WM_" + GoodR,["NAME"]) for row incursor: WMtxt.write(row[0] +"n") del cursor WMtxt.write("nVeryGoodCell Receptionn") cursor = arcpy.da.SearchCursor(gdbFullPath+""+ "WM_" + VGR,["NAME"]) for row incursor:
  • 12. WMtxt.write(row[0] +"n") del cursor WMtxt.write("nGreatCell Receptionn") cursor = arcpy.da.SearchCursor(gdbFullPath+""+ "WM_" + GR, ["NAME"]) for row incursor: WMtxt.write(row[0] +"n") del cursor WMtxt.close() print"WaterMeterList.txtwassucessfullycreatedandwritten" except: print"Failedtocreate WaterMeterList.txt" print"!!!!!!!!!!!!!Programhasfinishedrunning!!!!!!!!!!!!!!!!!!!!!"