Distance measuring is what the LIDARs and range finders are for. Most of them (because of weight and size limitations in drones) are used for small distances. You shouldn't have any problem finding a small rangefinder with high precision, if anything the max detecting range is what will limit you (there's some that have a max range of a few meters, 4 for example).
If you want to automatically detect the walls+ground, have the copter face the wall and get close to it, and take a picture (or activate video) this is perfectly possible. If anything you'll have to develop it yourself, but the sensors will enable you to get the necessary information. If you want a half sphere of detection (360º and below) you'll probably need multiple sensors depending on their capabilities.
Take into account that if you want to automate this you'll probably need 360º of range detection. On the other hand, you might give a try to manually moving the copter close to the wall, pointing the right side towards it, then activate the automated close-up. Also, safety-wise, remember that any air vehicle has issues getting close to walls and the like because of airflow-physics.