Used to be that RAW, the sniper wasn't getting the sneak attack. Why? No good reason other than that "a legalistic reading of the rules said so." There are no end of huge threads on paizo.com going over in tortuous detail how vision and stealth and all that work in PF core, especially here and here, and the summary was "slavishly following the rules means things that make no sense." You never get sneak attack from stealth because "you can't stealth while attacking" and "it doesn't say you get sneak attack just because someone can't see you, as hidden isn't an official condition (tm)."
I would previously invoke GM privilege to implement RAI - as in Pathfinder they say clearly "the GM is the law over and above the written rules" - and make it so they get their sneak attack. Because it makes sense from a game world logic/sim point of view and you can rule that's more important than the RAW point of view. IMO the clear intent was to sneak-attack someone from Stealth. You know, "sneak," "attack," things that happen in the real world and every previous edition of D&D.
Can I Attack From Stealth?
Now, however, the Stealth rules have been errata'ed to specifically say "you can attack from stealth" which means that yes, you get the sneak attack. See the updated version on the PRD which says:
Breaking Stealth: When you start your turn using Stealth, you can leave cover or concealment and remain unobserved as long as you succeed at a Stealth check and end your turn in cover or concealment. Your Stealth immediately ends after you make an attack roll, whether or not the attack is successful (except when sniping as noted below).
Sniping: If you've already successfully used Stealth at least 10 feet from your target, you can make one ranged attack and then immediately use Stealth again. You take a –20 penalty on your Stealth check to maintain your obscured location.
So the RAW has been updated to match the RAI for whatever that's worth (apparently it's really meaningful to some, though all my rogues have been happily sneak attacking from Stealth since the year 2000...).
Does A Stealthed Attack Enable Sneak Attack?
Yes, if you're stealthed, your attacks are sneak attacks.
Jason Buhlman states the intent clearly on the Paizo forums:
For simplicities sake, it should be assumed that those making Perception checks get to do so at the most favorable point during the movement of a character using Stealth, to avoid making checks every time the condition changes. Technically, I think you would get a check whenever the conditions change, but that might make things overly complicated during play.
Creatures are denied their Dexterity bonus to AC "if they cannot react to a blow" (CR pg 179 under AC). It was our intent that if you are unaware of a threat, you cannot react to a blow. I think we probably should have spelled this out a wee bit clearer, but space in the Stealth description was extraordinarily tight and ever word was at a premium. That said, I think these changes clear up the situation immensely (compared to where they were.. which was nebulous at best).
They didn't bother changing the RAW because most people use common sense and play it that way. Stealthed = sneak, etc.
RAW + Pathfinder = Sad Panda
This is why, whether you like this or not, a pure RAW approach to Pathfinder is always going to be frustrating; the devs explicitly don't bother to clean up RAW when RAI and/or common sense is clear. It's not a priority of theirs and I for one am pretty happy about that - they spend their intellectual capital making new interesting fun content instead of crafting rules and just retreading the same content year after year like WotC did with 3.5 (Return to the Return to the 1e Module, anyone?).
Coming Out From Behind The Wall
Maybe. Here's the thing. If the Rogue has to come into the open to do this, he's no longer hiding (you can't hide in the open). No spot check is needed to see the Rogue if he just walks out into clear sight of the Ogre, he's no longer hidden. As he's no longer hidden, he'll need some other condition to allow for a Sneak Attack (flanking for example).
This is one of the reasons why Hide In Plain Sight is so good. If you had that, the Rogue could attempt to remain hidden even out in the open and this would work. Shadowdancers for example can stay hidden if they're near a shadow. That would include the shadow of the wall or the Ogre itself, making it a LOT easier to attack while hidden.
Rules Compendium Changes
The Rules Compendium (page 92) adds some extra things to Hide, if you're using it. Those address coming out from hiding a bit differently. In this case the answer would be Yes, if you can make the new Hide check as detailed below.
Move between Cover: If you’re already hiding thanks to cover or
concealment, and you have at least 5 ranks in Hide, you can make a
Hide check (with a penalty) to try to move across an area that doesn’t
offer cover or concealment without revealing yourself. For every 5
ranks in Hide you possess, you can move up to 5 feet between one
hiding place and another. For every 5 feet of open space you must
cross between hiding places, you take a –5 penalty on your Hide check.
Movement speed penalizes the check as normal.
Sneak up from Hiding: You can sneak up on someone after emerging from a hiding place. For every 5 feet of open space between you and the target, you take a –5
penalty on your Hide check. If your Hide check succeeds, your target
doesn’t notice you until you attack or perform some other
attention-grabbing action. Such a target is treated as being flat-footed with respect to you.
Sniper
Yes. It's specifically mentioned in the Hide skill:
If you’ve already successfully hidden at least 10 feet from your target, you can make one ranged attack, then immediately hide
again. You take a -20 penalty on your Hide check to conceal yourself
after the shot.
Being aware of someone isn't enough to prevent Sneak Attack. If the spot checks fail against the new hide check, then the Rogue is hidden again and can continue to sneak attack.
Hiding and Sneak Attack
Yes, being hidden with Hide makes you effectively invisible, which normally allows Sneak Attack. Again from the Rules Compendium (p. 92):
If you’re successfully hidden with respect to another creature, that
creature is flat-footed with respect to you. That creature treats you
as if you were invisible (see page 76).
Best Answer
Sadly, the RAW answer is no. You can snipe and remain hidden, but your next attack is not a sneak attack because "stealthed" isn't a condition that makes a target flat-footed or denies it its Dex bonus to AC. Similarly, if you simply stay hidden until the battle is raging and try to shoot someone, it's not RAW a sneak attack. (It's not because it doesn't say it is, the rules are clear in omission.)
Of course this tends to defy reason, so I let people get in sneak attacks in other situations, as "it's the first round of a combat" is not a real in-game-world thing.
The devs understand the stealth rules are a big hot mess; in fact they posted some playtest new stealth rules on paizo.com in an attempt to come up with something less wonky.